##### R CODE TO REPLICATE THE MODELS INCLUDED IN 
##### Dawn Brancati and Adrian Lucardi, "Why Democracy Protests Do Not Diffuse," Journal of Conflict Resolution, 63(10), 2019, 2354-2389.

## Loading the required R packages. Make sure to have them installed before proceeding. In order to install a package called "X", write install.packages("X")
library (car)
library (dplyr)
library (lfe)
library (lme4)
library (plyr)
library (plm)
library (readstata13)
library (survival)
library (tidyr)

## display options
options (digits=4, scipen=6, show.signif.stars=FALSE, tibble.print_max = Inf)

## working directory -> change this to the directory where your have your data
setwd ("/Users/adrianlucardi/Documents/WashU/Research/Published/2019 JCR Democracy protests/Analysis/Replication/")



###### (1) DOWNLOADING AND PROCESSING THE DATA

### (1.1) Downloading

# Main dataset
system.time (base <- read.dta13 ("Neighbor protests 1989-2011.dta"))  ## 198 seconds
base$year <- as.numeric (format (base$date, "%Y"))
base$decade <- with (base, factor (ifelse (date <= "1999-12-31", "d1990", "d2000")))
base$country <- factor (base$country)
base$region <- factor (base$region)
base$id <- with (base, factor (paste (country, date, sep="_")))
base$countryYear <- with (base, factor (paste (country, year, sep="_")))
base$cdecade <- with (base, factor (paste (country, decade, sep="_")))
base$ryear <- with (base, factor (paste (region, year, sep="_")))
base$week <- NULL
base$month <- NULL
base$month2 <- NULL

# GDELT data
system.time (gdelt <- read.dta13 ("Neighbor protests 1989-2011 - GDELT data.dta"))  ## 15 seconds
gdelt$id <- factor (gdelt$id)
gdelt$protend45 <- NULL
gdelt$protend90 <- NULL
gdelt$protend120 <- NULL
gdelt <- merge (gdelt, base[,c ("id", "country", "date", "region", "pop_lag", "wdi_GDPcap_lag", "wdi_GDPcapGrowth_lag", "ele30", "polity", "autocracy")], by.x="id", by.y="id", all.x=T, all.y=T)

# SPEED data
system.time (speed <- read.dta13 ("Neighbor protests 1989-2005 - SPEED data.dta"))  ## 11 seconds
speed$id <- factor (speed$id)
speed$protend45 <- NULL
speed$protend90 <- NULL
speed$protend120 <- NULL
speed <- merge (speed, base[,c ("id", "country", "date", "region", "pop_lag", "wdi_GDPcap_lag", "wdi_GDPcapGrowth_lag", "ele30", "polity", "autocracy")], by.x="id", by.y="id", all.x=T, all.y=F)

# MMD data (Clark and Regan 2015)
system.time (mmd <- read.dta13 ("Neighbor protests 1990-2011 - MMD data.dta"))  ## 21 seconds
mmd$id <- factor (mmd$id)
mmd$protendMMD45 <- NULL
mmd$protendMMD90 <- NULL
mmd$protendMMD120 <- NULL
mmd <- merge (mmd, base[,c ("id", "country", "date", "region", "pop_lag", "wdi_GDPcap_lag", "wdi_GDPcapGrowth_lag", "ele30", "polity", "autocracy")], by.x="id", by.y="id", all.x=T, all.y=F)

# Bunce data
system.time (bunce <- read.dta13 ("Neighbor protests 1989-2011 - Bunce data.dta"))  ## 43 seconds
bunce$id <- factor (bunce$id)

# Weekly data
system.time (bweek <- read.dta13 ("Neighbor protests 1989-2011 - Weekly data.dta"))  ## 17 seconds
bweek <- bweek[bweek$inplace==0,]  ## to exclude observations in which a protest was already in place
bweek <- bweek[!is.na (bweek$country),]
bweek$date <- with (bweek, as.Date ("1989-01-01") + (week-1)*7) ## date as indicaed by the first day of the week
bweek$year <- as.numeric (format (bweek$date, "%Y"))
bweek$country <- factor (bweek$country)
bweek$region <- factor (bweek$region)
bweek$countryYear <- with (bweek, factor (paste (country, year, sep="_")))
bweek$id <- with (bweek, factor (paste (country, date, sep="_")))

# Monthly data
system.time (bmonth <- read.dta13 ("Neighbor protests 1989-2011 - Monthly data.dta"))  ## 4 seconds
bmonth <- bmonth[bmonth$inplace==0,]  ## to exclude observations in which a protest was already in place
bmonth <- bmonth[!is.na (bmonth$country),]
bmonth$year <- with (bmonth, floor (month/12))  ## largest integer
bmonth$country <- factor (bmonth$country)
bmonth$region <- factor (bmonth$region)
bmonth$countryYear <- with (bmonth, factor (paste (country, year, sep="_")))
bmonth$cweek <- factor (bmonth$cmonth)

# Yearly data
system.time (byear <- read.dta13 ("Neighbor protests 1989-2011 - Yearly data.dta"))  ## 0.1 seconds
byear <- byear[byear$inplace==0,]  ## to exclude observations in which a protest was already in place
byear <- byear[!is.na (byear$country),]
byear$year <- as.numeric (format (byear$date, "%Y"))
byear$country <- factor (byear$country)
byear$region <- factor (byear$region)
byear$countryYear <- with (byear, factor (paste (country, year, sep="_")))

# Arab Spring data -> additional protests for Tunisia, Libya and Syria
system.time (bspring <- read.dta13 ("Neighbor protests 1989-2011 - Arab Spring.dta"))  ## 205 seconds
bspring <- bspring[bspring$inplace==0,]  ## to exclude observations in which a protest was already in place
bspring$year <- as.numeric (format (bspring$date, "%Y"))
bspring$country <- factor (bspring$country)
bspring$region <- factor (bspring$region)
bspring$id <- with (bspring, factor (paste (country, date, sep="_")))
bspring$countryYear <- with (bspring, factor (paste (country, year, sep="_")))
bspring$week <- NULL
bspring$month <- NULL
bspring$month2 <- NULL
bspring$cmonth <- NULL
bspring$cweek <- NULL

# MENA sample -> neighborhood calculated only among countries in the region
system.time (bmena <- read.dta13 ("Neighbor protests 1989-2011 - MENA sample.dta"))  ## 28 seconds
bmena <- bmena[bmena$inplace==0,]  ## to exclude observations in which a protest was already in place
bmena <- bmena[!is.na (bmena$country),]
bmena$year <- as.numeric (format (bmena$date, "%Y"))
bmena$country <- factor (bmena$country)
bmena$region <- factor (bmena$region)
bmena$id <- with (bmena, factor (paste (country, date, sep="_")))
bmena$countryYear <- with (bmena, factor (paste (country, year, sep="_")))
bmena$month <- NULL

# Venezuela -> same as main dataset, but including the 2007 Venezuelan protests (which affects the neighbor values for all other observations)
system.time (vzla <- read.dta13 ("Neighbor protests 1989-2011 - Venezuela.dta"))  ## 137 seconds
vzla$year <- as.numeric (format (vzla$date, "%Y"))
vzla$country <- factor (vzla$country)
vzla$region <- factor (vzla$region)
vzla$id <- with (vzla, factor (paste (country, date, sep="_")))
vzla$countryYear <- with (vzla, factor (paste (country, year, sep="_")))
vzla$week <- NULL
vzla$month <- NULL
vzla$month2 <- NULL

# V-Dem v8.0
vdem2 <- read.dta13 ("V-Dem-CY+Others-v8.dta")

# selecting the variables of interest
vdem <- vdem2[vdem2$year >= 1989 & vdem2$year <= 2011,c (

  # ID variables
  "country_name", "year"

  # political civil liberties index
  , "v2x_clpol"

  # freedom of expression index (0 to 1)
  , "v2x_freexp"

  # government censorship effort - Media
  , "v2mecenefm", "v2mecenefm_osp"

  # harassment of journalists
  , "v2meharjrn", "v2meharjrn_osp"

  # media self-censorship
  , "v2meslfcen", "v2meslfcen_osp"
  )]
vdem2 <- NULL


## checking whether a neighbor protest during t-1 leads to lower media freedom in t

# we first restrict the dataset to the first day of the year
media2 <- base[grep ("-12-31", base$date),] ## i.e., last day of the year only

# creating some additional variables
media2$country <- factor (media2$country)
media2$region <- factor (media2$region)
media2$year <- as.numeric (format (media2$date, "%Y"))
media2$id <- with (media2, factor (paste (country, year, sep="_")))

# eliminating others
media2$date <- NULL
discard <- c (grep ("_d45_", colnames (media2)), grep ("_d90_", colnames (media2)), grep ("_d120_", colnames (media2))) ## we're only interested in what happened within 360 days of December 31st of any given year -i.e., practically during the previous year
media <- media2[,-discard]

# adding the V-Dem data -> checking that country names coincide
summary (sort (unique (media$country)) %in% sort (unique (vdem$country_name))) ## 20 discrepancies:
sort (unique (media$country))[sort (unique (media$country)) %in% sort (unique (vdem$country_name))==FALSE]

# same countries with different name
vdem[vdem$country_name=="Burma/Myanmar",]$country_name <- "Myanmar/Burma"
vdem[vdem$country_name=="Czech Republic" & vdem$year<=1992,]$country_name <- "Czechoslovakia"
vdem[vdem$country_name=="Democratic Republic of Congo",]$country_name <- "Congo, Democratic Republic of"
vdem[vdem$country_name=="Democratic Republic of Vietnam",]$country_name <- "Vietnam"
vdem[vdem$country_name=="German Democratic Republic",]$country_name <- "East Germany"
vdem[vdem$country_name=="Germany" & vdem$year==1989,]$country_name <- "Germany Federal Republic"
vdem[vdem$country_name=="Republic of the Congo",]$country_name <- "Congo, Republic of"
vdem[vdem$country_name=="Russia" & vdem$year<=1990,]$country_name <- "Soviet Union"
vdem[grep ("cipe", vdem$country_name),]$country_name <- "Sao Tome and Principe"
vdem[vdem$country_name=="Serbia" & vdem$year>=1993 & vdem$year <= 2005,]$country_name <- "Serbia and Montenegro"
vdem[vdem$country_name=="South Yemen",]$country_name <- "Yemen People's Republic"
vdem[vdem$country_name=="Solomon Islands",]$country_name <- "Solomon Is."
vdem[vdem$country_name=="Timor-Leste",]$country_name <- "Timor Leste"
vdem[vdem$country_name=="United States of America",]$country_name <- "United States"
vdem[vdem$country_name=="Yemen" & vdem$year==1989,]$country_name <- "Yemen Arab Republic"

summary (sort (unique (media$country)) %in% sort (unique (vdem$country_name))) ## only 5 discrepancies remain. All of them correspond to countries not in V-DeM:
sort (unique (media$country))[sort (unique (media$country)) %in% sort (unique (vdem$country_name))==FALSE]
# Bahamas
# Belize
# Brunei
# Malta
# Yugoslavia

# looking the other way down:
summary (sort (unique (vdem$country_name)) %in% sort (unique (media$country))) ## 7 discrepancies, all corresponding to countries for which we don't have data. Good:
sort (unique (vdem$country_name))[sort (unique (vdem$country_name)) %in% sort (unique (media$country))==FALSE]

# merging
vdem$id <- with (vdem, factor (paste (country_name, year, sep="_")))
vdem$country_name <- NULL
vdem$year <- NULL

media <- merge (media, vdem, by.x="id", by.y="id", all.x=T, all.y=F)
media <- media[!is.na (media$v2x_freexp),]
media$id <- factor (media$id)
media$country <- factor (media$country)
media$region <- factor (media$region)

# getting previous year's values to first-difference:
mediaLag <- media[,c ("country", "year", "polity", "n50_d360_wequal_any", "n50_d360_wequal_sum", "n50_d360_wSize_any", "n800_d360_wequal_any", "n800_d360_wequal_sum", "n800_d360_wSize_any", "nUN_d360_wequal_any", "nUN_d360_wequal_sum", "nUN_d360_wSize_any", "v2x_clpol", "v2x_freexp", "v2mecenefm", "v2meharjrn", "v2meslfcen")]
mediaLag$year <- mediaLag$year - 1
mediaLag$id <- with (mediaLag, factor (paste (country, year, sep="_")))

mediaLag$country <- NULL
mediaLag$year <- NULL
colnames (mediaLag) <- paste (colnames (mediaLag), "lag", sep="_")

# merging
media <- merge (media, mediaLag, by.x="id", by.y="id_lag", all.x=T, all.y=F)

# getting logged values for some variables
media$pop <- log (media$pop)
media$pop_lag <- log (media$pop_lag)
media$wdi_GDPcap <- log (media$wdi_GDPcap)
media$wdi_GDPcap_lag <- log (media$wdi_GDPcap_lag)

# calculating the first differences
media$pop_ch <- with (media, pop - pop_lag)
media$wdi_GDPcap_ch <- with (media, wdi_GDPcap - wdi_GDPcap_lag)
media$physint_ch <- with (media, physint - physint_lag)
media$polity_ch <- with (media, polity - polity_lag)

media$n50_d360_wequal_any_ch <- with (media, n50_d360_wequal_any - n50_d360_wequal_any_lag)
media$n800_d360_wequal_any_ch <- with (media, n800_d360_wequal_any - n800_d360_wequal_any_lag)
media$nUN_d360_wequal_any_ch <- with (media, nUN_d360_wequal_any - nUN_d360_wequal_any_lag)
media$n50_d360_wequal_sum_ch <- with (media, n50_d360_wequal_sum - n50_d360_wequal_sum_lag)
media$n800_d360_wequal_sum_ch <- with (media, n800_d360_wequal_sum - n800_d360_wequal_sum_lag)
media$nUN_d360_wequal_sum_ch <- with (media, nUN_d360_wequal_sum - nUN_d360_wequal_sum_lag)
media$n50_d360_wSize_any_ch <- with (media, n50_d360_wSize_any - n50_d360_wSize_any_lag)
media$n800_d360_wSize_any_ch <- with (media, n800_d360_wSize_any - n800_d360_wSize_any_lag)
media$nUN_d360_wSize_any_ch <- with (media, nUN_d360_wSize_any - nUN_d360_wSize_any_lag)
media$v2x_clpol_ch <- with (media, v2x_clpol - v2x_clpol_lag)
media$v2x_freexp_ch <- with (media, v2x_freexp - v2x_freexp_lag)
media$v2mecenefm_ch <- with (media, v2mecenefm - v2mecenefm_lag)
media$v2meharjrn_ch <- with (media, v2meharjrn - v2meharjrn_lag)
media$v2meslfcen_ch <- with (media, v2meslfcen - v2meslfcen_lag)


### (1.2) Processing

## Main dataset -> transforming and factorizing the successful/unsuccessful variables (ditto for repressed/not repressed and violent/non-violent)

# we first exclude protests that were already in place:
base <- base[base$inplace==0,]  ## to exclude observations in which a protest was already in place
base$decade <- factor (base$decade)
base$country <- factor (base$country)
base$region <- factor (base$region)
base$id <- factor (base$id)
base$cdecade <- factor (base$cdecade)
base$countryYear <- factor (base$countryYear)
base$ryear <- factor (base$ryear)
base$cmonth <- factor (base$cmonth)
base$cweek <- factor (base$cweek)

# (a) Protest success
base$n50_d45_wSuc_any2 <- factor (with (base, ifelse (
  n50_d45_wSuc_any==0 & n50_d45_wunSuc_any==0, "01-no protests", ifelse (
    n50_d45_wSuc_any==1 & n50_d45_wunSuc_any==0, "02-all successful", ifelse (
      n50_d45_wSuc_any==1 & n50_d45_wunSuc_any==1, "03-some successful", "04-none successful")))))
base$n50_d90_wSuc_any2 <- factor (with (base, ifelse (
  n50_d90_wSuc_any==0 & n50_d90_wunSuc_any==0, "01-no protests", ifelse (
    n50_d90_wSuc_any==1 & n50_d90_wunSuc_any==0, "02-all successful", ifelse (
      n50_d90_wSuc_any==1 & n50_d90_wunSuc_any==1, "03-some successful", "04-none successful")))))
base$n50_d120_wSuc_any2 <- factor (with (base, ifelse (
  n50_d120_wSuc_any==0 & n50_d120_wunSuc_any==0, "01-no protests", ifelse (
    n50_d120_wSuc_any==1 & n50_d120_wunSuc_any==0, "02-all successful", ifelse (
      n50_d120_wSuc_any==1 & n50_d120_wunSuc_any==1, "03-some successful", "04-none successful")))))
base$n800_d45_wSuc_any2 <- factor (with (base, ifelse (
  n800_d45_wSuc_any==0 & n800_d45_wunSuc_any==0, "01-no protests", ifelse (
    n800_d45_wSuc_any==1 & n800_d45_wunSuc_any==0, "02-all successful", ifelse (
      n800_d45_wSuc_any==1 & n800_d45_wunSuc_any==1, "03-some successful", "04-none successful")))))
base$n800_d90_wSuc_any2 <- factor (with (base, ifelse (
  n800_d90_wSuc_any==0 & n800_d90_wunSuc_any==0, "01-no protests", ifelse (
    n800_d90_wSuc_any==1 & n800_d90_wunSuc_any==0, "02-all successful", ifelse (
      n800_d90_wSuc_any==1 & n800_d90_wunSuc_any==1, "03-some successful", "04-none successful")))))
base$n800_d120_wSuc_any2 <- factor (with (base, ifelse (
  n800_d120_wSuc_any==0 & n800_d120_wunSuc_any==0, "01-no protests", ifelse (
    n800_d120_wSuc_any==1 & n800_d120_wunSuc_any==0, "02-all successful", ifelse (
      n800_d120_wSuc_any==1 & n800_d120_wunSuc_any==1, "03-some successful", "04-none successful")))))
base$nUN_d45_wSuc_any2 <- factor (with (base, ifelse (
  nUN_d45_wSuc_any==0 & nUN_d45_wunSuc_any==0, "01-no protests", ifelse (
    nUN_d45_wSuc_any==1 & nUN_d45_wunSuc_any==0, "02-all successful", ifelse (
      nUN_d45_wSuc_any==1 & nUN_d45_wunSuc_any==1, "03-some successful", "04-none successful")))))
base$nUN_d90_wSuc_any2 <- factor (with (base, ifelse (
  nUN_d90_wSuc_any==0 & nUN_d90_wunSuc_any==0, "01-no protests", ifelse (
    nUN_d90_wSuc_any==1 & nUN_d90_wunSuc_any==0, "02-all successful", ifelse (
      nUN_d90_wSuc_any==1 & nUN_d90_wunSuc_any==1, "03-some successful", "04-none successful")))))
base$nUN_d120_wSuc_any2 <- factor (with (base, ifelse (
  nUN_d120_wSuc_any==0 & nUN_d120_wunSuc_any==0, "01-no protests", ifelse (
    nUN_d120_wSuc_any==1 & nUN_d120_wunSuc_any==0, "02-all successful", ifelse (
      nUN_d120_wSuc_any==1 & nUN_d120_wunSuc_any==1, "03-some successful", "04-none successful")))))

# (b) Protest success (excluding cases of non-genuine accomodation)
base$n50_d45_wSuc2_any2 <- factor (with (base, ifelse (
  n50_d45_wSuc2_any==0 & n50_d45_wunSuc2_any==0, "01-no protests", ifelse (
    n50_d45_wSuc2_any==1 & n50_d45_wunSuc2_any==0, "02-all successful", ifelse (
      n50_d45_wSuc2_any==1 & n50_d45_wunSuc2_any==1, "03-some successful", "04-none successful")))))
base$n50_d90_wSuc2_any2 <- factor (with (base, ifelse (
  n50_d90_wSuc2_any==0 & n50_d90_wunSuc2_any==0, "01-no protests", ifelse (
    n50_d90_wSuc2_any==1 & n50_d90_wunSuc2_any==0, "02-all successful", ifelse (
      n50_d90_wSuc2_any==1 & n50_d90_wunSuc2_any==1, "03-some successful", "04-none successful")))))
base$n50_d120_wSuc2_any2 <- factor (with (base, ifelse (
  n50_d120_wSuc2_any==0 & n50_d120_wunSuc2_any==0, "01-no protests", ifelse (
    n50_d120_wSuc2_any==1 & n50_d120_wunSuc2_any==0, "02-all successful", ifelse (
      n50_d120_wSuc2_any==1 & n50_d120_wunSuc2_any==1, "03-some successful", "04-none successful")))))
base$n800_d45_wSuc2_any2 <- factor (with (base, ifelse (
  n800_d45_wSuc2_any==0 & n800_d45_wunSuc2_any==0, "01-no protests", ifelse (
    n800_d45_wSuc2_any==1 & n800_d45_wunSuc2_any==0, "02-all successful", ifelse (
      n800_d45_wSuc2_any==1 & n800_d45_wunSuc2_any==1, "03-some successful", "04-none successful")))))
base$n800_d90_wSuc2_any2 <- factor (with (base, ifelse (
  n800_d90_wSuc2_any==0 & n800_d90_wunSuc2_any==0, "01-no protests", ifelse (
    n800_d90_wSuc2_any==1 & n800_d90_wunSuc2_any==0, "02-all successful", ifelse (
      n800_d90_wSuc2_any==1 & n800_d90_wunSuc2_any==1, "03-some successful", "04-none successful")))))
base$n800_d120_wSuc2_any2 <- factor (with (base, ifelse (
  n800_d120_wSuc2_any==0 & n800_d120_wunSuc2_any==0, "01-no protests", ifelse (
    n800_d120_wSuc2_any==1 & n800_d120_wunSuc2_any==0, "02-all successful", ifelse (
      n800_d120_wSuc2_any==1 & n800_d120_wunSuc2_any==1, "03-some successful", "04-none successful")))))
base$nUN_d45_wSuc2_any2 <- factor (with (base, ifelse (
  nUN_d45_wSuc2_any==0 & nUN_d45_wunSuc2_any==0, "01-no protests", ifelse (
    nUN_d45_wSuc2_any==1 & nUN_d45_wunSuc2_any==0, "02-all successful", ifelse (
      nUN_d45_wSuc2_any==1 & nUN_d45_wunSuc2_any==1, "03-some successful", "04-none successful")))))
base$nUN_d90_wSuc2_any2 <- factor (with (base, ifelse (
  nUN_d90_wSuc2_any==0 & nUN_d90_wunSuc2_any==0, "01-no protests", ifelse (
    nUN_d90_wSuc2_any==1 & nUN_d90_wunSuc2_any==0, "02-all successful", ifelse (
      nUN_d90_wSuc2_any==1 & nUN_d90_wunSuc2_any==1, "03-some successful", "04-none successful")))))
base$nUN_d120_wSuc2_any2 <- factor (with (base, ifelse (
  nUN_d120_wSuc2_any==0 & nUN_d120_wunSuc2_any==0, "01-no protests", ifelse (
    nUN_d120_wSuc2_any==1 & nUN_d120_wunSuc2_any==0, "02-all successful", ifelse (
      nUN_d120_wSuc2_any==1 & nUN_d120_wunSuc2_any==1, "03-some successful", "04-none successful")))))

# (c) Protest repression
base$n50_d45_wRepr_any2 <- factor (with (base, ifelse (
  n50_d45_wRepr_any==0 & n50_d45_wunRepr_any==0, "01-no protests", ifelse (
    n50_d45_wRepr_any==1 & n50_d45_wunRepr_any==0, "02-all repressed", ifelse (
      n50_d45_wRepr_any==1 & n50_d45_wunRepr_any==1, "03-some repressed", "04-none repressed")))))
base$n50_d90_wRepr_any2 <- factor (with (base, ifelse (
  n50_d90_wRepr_any==0 & n50_d90_wunRepr_any==0, "01-no protests", ifelse (
    n50_d90_wRepr_any==1 & n50_d90_wunRepr_any==0, "02-all repressed", ifelse (
      n50_d90_wRepr_any==1 & n50_d90_wunRepr_any==1, "03-some repressed", "04-none repressed")))))
base$n50_d120_wRepr_any2 <- factor (with (base, ifelse (
  n50_d120_wRepr_any==0 & n50_d120_wunRepr_any==0, "01-no protests", ifelse (
    n50_d120_wRepr_any==1 & n50_d120_wunRepr_any==0, "02-all repressed", ifelse (
      n50_d120_wRepr_any==1 & n50_d120_wunRepr_any==1, "03-some repressed", "04-none repressed")))))
base$n800_d45_wRepr_any2 <- factor (with (base, ifelse (
  n800_d45_wRepr_any==0 & n800_d45_wunRepr_any==0, "01-no protests", ifelse (
    n800_d45_wRepr_any==1 & n800_d45_wunRepr_any==0, "02-all repressed", ifelse (
      n800_d45_wRepr_any==1 & n800_d45_wunRepr_any==1, "03-some repressed", "04-none repressed")))))
base$n800_d90_wRepr_any2 <- factor (with (base, ifelse (
  n800_d90_wRepr_any==0 & n800_d90_wunRepr_any==0, "01-no protests", ifelse (
    n800_d90_wRepr_any==1 & n800_d90_wunRepr_any==0, "02-all repressed", ifelse (
      n800_d90_wRepr_any==1 & n800_d90_wunRepr_any==1, "03-some repressed", "04-none repressed")))))
base$n800_d120_wRepr_any2 <- factor (with (base, ifelse (
  n800_d120_wRepr_any==0 & n800_d120_wunRepr_any==0, "01-no protests", ifelse (
    n800_d120_wRepr_any==1 & n800_d120_wunRepr_any==0, "02-all repressed", ifelse (
      n800_d120_wRepr_any==1 & n800_d120_wunRepr_any==1, "03-some repressed", "04-none repressed")))))
base$nUN_d45_wRepr_any2 <- factor (with (base, ifelse (
  nUN_d45_wRepr_any==0 & nUN_d45_wunRepr_any==0, "01-no protests", ifelse (
    nUN_d45_wRepr_any==1 & nUN_d45_wunRepr_any==0, "02-all repressed", ifelse (
      nUN_d45_wRepr_any==1 & nUN_d45_wunRepr_any==1, "03-some repressed", "04-none repressed")))))
base$nUN_d90_wRepr_any2 <- factor (with (base, ifelse (
  nUN_d90_wRepr_any==0 & nUN_d90_wunRepr_any==0, "01-no protests", ifelse (
    nUN_d90_wRepr_any==1 & nUN_d90_wunRepr_any==0, "02-all repressed", ifelse (
      nUN_d90_wRepr_any==1 & nUN_d90_wunRepr_any==1, "03-some repressed", "04-none repressed")))))
base$nUN_d120_wRepr_any2 <- factor (with (base, ifelse (
  nUN_d120_wRepr_any==0 & nUN_d120_wunRepr_any==0, "01-no protests", ifelse (
    nUN_d120_wRepr_any==1 & nUN_d120_wunRepr_any==0, "02-all repressed", ifelse (
      nUN_d120_wRepr_any==1 & nUN_d120_wunRepr_any==1, "03-some repressed", "04-none repressed")))))

# (d) Protest violence
base$n50_d45_wViol_any2 <- factor (with (base, ifelse (
  n50_d45_wViol_any==0 & n50_d45_wunViol_any==0, "01-no protests", ifelse (
    n50_d45_wViol_any==1 & n50_d45_wunViol_any==0, "02-all violent", ifelse (
      n50_d45_wViol_any==1 & n50_d45_wunViol_any==1, "03-some violent", "04-none violent")))))
base$n50_d90_wViol_any2 <- factor (with (base, ifelse (
  n50_d90_wViol_any==0 & n50_d90_wunViol_any==0, "01-no protests", ifelse (
    n50_d90_wViol_any==1 & n50_d90_wunViol_any==0, "02-all violent", ifelse (
      n50_d90_wViol_any==1 & n50_d90_wunViol_any==1, "03-some violent", "04-none violent")))))
base$n50_d120_wViol_any2 <- factor (with (base, ifelse (
  n50_d120_wViol_any==0 & n50_d120_wunViol_any==0, "01-no protests", ifelse (
    n50_d120_wViol_any==1 & n50_d120_wunViol_any==0, "02-all violent", ifelse (
      n50_d120_wViol_any==1 & n50_d120_wunViol_any==1, "03-some violent", "04-none violent")))))
base$n800_d45_wViol_any2 <- factor (with (base, ifelse (
  n800_d45_wViol_any==0 & n800_d45_wunViol_any==0, "01-no protests", ifelse (
    n800_d45_wViol_any==1 & n800_d45_wunViol_any==0, "02-all violent", ifelse (
      n800_d45_wViol_any==1 & n800_d45_wunViol_any==1, "03-some violent", "04-none violent")))))
base$n800_d90_wViol_any2 <- factor (with (base, ifelse (
  n800_d90_wViol_any==0 & n800_d90_wunViol_any==0, "01-no protests", ifelse (
    n800_d90_wViol_any==1 & n800_d90_wunViol_any==0, "02-all violent", ifelse (
      n800_d90_wViol_any==1 & n800_d90_wunViol_any==1, "03-some violent", "04-none violent")))))
base$n800_d120_wViol_any2 <- factor (with (base, ifelse (
  n800_d120_wViol_any==0 & n800_d120_wunViol_any==0, "01-no protests", ifelse (
    n800_d120_wViol_any==1 & n800_d120_wunViol_any==0, "02-all violent", ifelse (
      n800_d120_wViol_any==1 & n800_d120_wunViol_any==1, "03-some violent", "04-none violent")))))
base$nUN_d45_wViol_any2 <- factor (with (base, ifelse (
  nUN_d45_wViol_any==0 & nUN_d45_wunViol_any==0, "01-no protests", ifelse (
    nUN_d45_wViol_any==1 & nUN_d45_wunViol_any==0, "02-all violent", ifelse (
      nUN_d45_wViol_any==1 & nUN_d45_wunViol_any==1, "03-some violent", "04-none violent")))))
base$nUN_d90_wViol_any2 <- factor (with (base, ifelse (
  nUN_d90_wViol_any==0 & nUN_d90_wunViol_any==0, "01-no protests", ifelse (
    nUN_d90_wViol_any==1 & nUN_d90_wunViol_any==0, "02-all violent", ifelse (
      nUN_d90_wViol_any==1 & nUN_d90_wunViol_any==1, "03-some violent", "04-none violent")))))
base$nUN_d120_wViol_any2 <- factor (with (base, ifelse (
  nUN_d120_wViol_any==0 & nUN_d120_wunViol_any==0, "01-no protests", ifelse (
    nUN_d120_wViol_any==1 & nUN_d120_wunViol_any==0, "02-all violent", ifelse (
      nUN_d120_wViol_any==1 & nUN_d120_wunViol_any==1, "03-some violent", "04-none violent")))))




########## (2) MAIN RESULTS

### (2.1) Descriptive statistics

## (2.1.2) Replicating the data reported in Table 2: Data Overview

# (a) contiguous neighbors
(tabCont30 <- with (base, prop.table (table (pbega, n50_d30_wequal_any), 2))*100)
(tabCont45 <- with (base, prop.table (table (pbega, n50_d45_wequal_any), 2))*100)
(tabCont90 <- with (base, prop.table (table (pbega, n50_d90_wequal_any), 2))*100)
(tabCont120 <- with (base, prop.table (table (pbega, n50_d120_wequal_any), 2))*100)

(tabCont30abs <- with (base, table (pbega, n50_d30_wequal_any)))
(tabCont45abs <- with (base, table (pbega, n50_d45_wequal_any)))
(tabCont90abs <- with (base, table (pbega, n50_d90_wequal_any)))
(tabCont120abs <- with (base, table (pbega, n50_d120_wequal_any)))

# t-tests
(tvalCont30 <- t.test (x=base[base$n50_d30_wequal_any==0,]$pbega, y=base[base$n50_d30_wequal_any==1,]$pbega))
(tvalCont45 <- t.test (x=base[base$n50_d45_wequal_any==0,]$pbega, y=base[base$n50_d45_wequal_any==1,]$pbega))
(tvalCont90 <- t.test (x=base[base$n50_d90_wequal_any==0,]$pbega, y=base[base$n50_d90_wequal_any==1,]$pbega))
(tvalCont120 <- t.test (x=base[base$n50_d120_wequal_any==0,]$pbega, y=base[base$n50_d120_wequal_any==1,]$pbega))

# (b) 800km neighbors
(tabN800.30 <- with (base, prop.table (table (pbega, n800_d30_wequal_any), 2))*100)
(tabN800.45 <- with (base, prop.table (table (pbega, n800_d45_wequal_any), 2))*100)
(tabN800.90 <- with (base, prop.table (table (pbega, n800_d90_wequal_any), 2))*100)
(tabN800.120 <- with (base, prop.table (table (pbega, n800_d120_wequal_any), 2))*100)

(tabN800.30abs <- with (base, table (pbega, n800_d30_wequal_any)))
(tabN800.45abs <- with (base, table (pbega, n800_d45_wequal_any)))
(tabN800.90abs <- with (base, table (pbega, n800_d90_wequal_any)))
(tabN800.120abs <- with (base, table (pbega, n800_d120_wequal_any)))

# t-tests
(tvalN800.30 <- t.test (x=base[base$n800_d30_wequal_any==0,]$pbega, y=base[base$n800_d30_wequal_any==1,]$pbega))
(tvalN800.45 <- t.test (x=base[base$n800_d45_wequal_any==0,]$pbega, y=base[base$n800_d45_wequal_any==1,]$pbega))
(tvalN800.90 <- t.test (x=base[base$n800_d90_wequal_any==0,]$pbega, y=base[base$n800_d90_wequal_any==1,]$pbega))
(tvalN800.120 <- t.test (x=base[base$n800_d120_wequal_any==0,]$pbega, y=base[base$n800_d120_wequal_any==1,]$pbega))

# (c) UN region neighbors
(tabUNReg30 <- with (base, prop.table (table (pbega, nUN_d30_wequal_any), 2))*100)
(tabUNReg45 <- with (base, prop.table (table (pbega, nUN_d45_wequal_any), 2))*100)
(tabUNReg90 <- with (base, prop.table (table (pbega, nUN_d90_wequal_any), 2))*100)
(tabUNReg120 <- with (base, prop.table (table (pbega, nUN_d120_wequal_any), 2))*100)

(tabUNReg30abs <- with (base, table (pbega, nUN_d30_wequal_any)))
(tabUNReg45abs <- with (base, table (pbega, nUN_d45_wequal_any)))
(tabUNReg90abs <- with (base, table (pbega, nUN_d90_wequal_any)))
(tabUNReg120abs <- with (base, table (pbega, nUN_d120_wequal_any)))

# t-tests
(tvalUNReg30 <- t.test (x=base[base$nUN_d30_wequal_any==0,]$pbega, y=base[base$nUN_d30_wequal_any==1,]$pbega))
(tvalUNReg45 <- t.test (x=base[base$nUN_d45_wequal_any==0,]$pbega, y=base[base$nUN_d45_wequal_any==1,]$pbega))
(tvalUNReg90 <- t.test (x=base[base$nUN_d90_wequal_any==0,]$pbega, y=base[base$nUN_d90_wequal_any==1,]$pbega))
(tvalUNReg120 <- t.test (x=base[base$nUN_d120_wequal_any==0,]$pbega, y=base[base$nUN_d120_wequal_any==1,]$pbega))


## (2.1.3) Replicating the data reported in Table A59: Data Overview, post-election periods only

# (a) contiguous neighbors
(tabCont.ele45 <- with (base[base$ele30==1,], prop.table (table (pbega, n50_d45_wequal_any), 2))*100)
(tabCont.ele90 <- with (base[base$ele30==1,], prop.table (table (pbega, n50_d90_wequal_any), 2))*100)
(tabCont.ele120 <- with (base[base$ele30==1,], prop.table (table (pbega, n50_d120_wequal_any), 2))*100)

(tabCont.ele45abs <- with (base[base$ele30==1,], table (pbega, n50_d45_wequal_any)))
(tabCont.ele90abs <- with (base[base$ele30==1,], table (pbega, n50_d90_wequal_any)))
(tabCont.ele120abs <- with (base[base$ele30==1,], table (pbega, n50_d120_wequal_any)))

# t-tests
(tvalCont.ele45 <- t.test (x=base[base$ele30==1 & base$n50_d45_wequal_any==0,]$pbega, y=base[base$ele30==1 & base$n50_d45_wequal_any==1,]$pbega))
(tvalCont.ele90 <- t.test (x=base[base$ele30==1 & base$n50_d90_wequal_any==0,]$pbega, y=base[base$ele30==1 & base$n50_d90_wequal_any==1,]$pbega))
(tvalCont.ele120 <- t.test (x=base[base$ele30==1 & base$n50_d120_wequal_any==0,]$pbega, y=base[base$ele30==1 & base$n50_d120_wequal_any==1,]$pbega))

# (b) 800km neighbors
(tabN800.ele45 <- with (base[base$ele30==1,], prop.table (table (pbega, n800_d45_wequal_any), 2))*100)
(tabN800.ele90 <- with (base[base$ele30==1,], prop.table (table (pbega, n800_d90_wequal_any), 2))*100)
(tabN800.ele120 <- with (base[base$ele30==1,], prop.table (table (pbega, n800_d120_wequal_any), 2))*100)

(tabN800.ele45abs <- with (base[base$ele30==1,], table (pbega, n800_d45_wequal_any)))
(tabN800.ele90abs <- with (base[base$ele30==1,], table (pbega, n800_d90_wequal_any)))
(tabN800.ele120abs <- with (base[base$ele30==1,], table (pbega, n800_d120_wequal_any)))

# t-tests
(tvalN800.ele45 <- t.test (x=base[base$ele30==1 & base$n800_d45_wequal_any==0,]$pbega, y=base[base$ele30==1 & base$n800_d45_wequal_any==1,]$pbega))
(tvalN800.ele90 <- t.test (x=base[base$ele30==1 & base$n800_d90_wequal_any==0,]$pbega, y=base[base$ele30==1 & base$n800_d90_wequal_any==1,]$pbega))
(tvalN800.ele120 <- t.test (x=base[base$ele30==1 & base$n800_d120_wequal_any==0,]$pbega, y=base[base$ele30==1 & base$n800_d120_wequal_any==1,]$pbega))

# (c) UN region neighbors
(tabUNReg.ele45 <- with (base[base$ele30==1,], prop.table (table (pbega, nUN_d45_wequal_any), 2))*100)
(tabUNReg.ele90 <- with (base[base$ele30==1,], prop.table (table (pbega, nUN_d90_wequal_any), 2))*100)
(tabUNReg.ele120 <- with (base[base$ele30==1,], prop.table (table (pbega, nUN_d120_wequal_any), 2))*100)

(tabUNReg.ele45abs <- with (base[base$ele30==1,], table (pbega, nUN_d45_wequal_any)))
(tabUNReg.ele90abs <- with (base[base$ele30==1,], table (pbega, nUN_d90_wequal_any)))
(tabUNReg.ele120abs <- with (base[base$ele30==1,], table (pbega, nUN_d120_wequal_any)))

# t-tests
(tvalUNReg.ele45 <- t.test (x=base[base$ele30==1 & base$nUN_d45_wequal_any==0,]$pbega, y=base[base$ele30==1 & base$nUN_d45_wequal_any==1,]$pbega))
(tvalUNReg.ele90 <- t.test (x=base[base$ele30==1 & base$nUN_d90_wequal_any==0,]$pbega, y=base[base$ele30==1 & base$nUN_d90_wequal_any==1,]$pbega))
(tvalUNReg.ele120 <- t.test (x=base[base$ele30==1 & base$nUN_d120_wequal_any==0,]$pbega, y=base[base$ele30==1 & base$nUN_d120_wequal_any==1,]$pbega))


## (2.1.4) Replicating the data reported in Table A60: Data Overview, non-election periods only

# (a) contiguous neighbors
(tabCont.noele45 <- with (base[base$ele30==0,], prop.table (table (pbega, n50_d45_wequal_any), 2))*100)
(tabCont.noele90 <- with (base[base$ele30==0,], prop.table (table (pbega, n50_d90_wequal_any), 2))*100)
(tabCont.noele120 <- with (base[base$ele30==0,], prop.table (table (pbega, n50_d120_wequal_any), 2))*100)

(tabCont.noele45abs <- with (base[base$ele30==0,], table (pbega, n50_d45_wequal_any)))
(tabCont.noele90abs <- with (base[base$ele30==0,], table (pbega, n50_d90_wequal_any)))
(tabCont.noele120abs <- with (base[base$ele30==0,], table (pbega, n50_d120_wequal_any)))

# t-tests
(tvalCont.noele45 <- t.test (x=base[base$ele30==0 & base$n50_d45_wequal_any==0,]$pbega, y=base[base$ele30==0 & base$n50_d45_wequal_any==1,]$pbega))
(tvalCont.noele90 <- t.test (x=base[base$ele30==0 & base$n50_d90_wequal_any==0,]$pbega, y=base[base$ele30==0 & base$n50_d90_wequal_any==1,]$pbega))
(tvalCont.noele120 <- t.test (x=base[base$ele30==0 & base$n50_d120_wequal_any==0,]$pbega, y=base[base$ele30==0 & base$n50_d120_wequal_any==1,]$pbega))

# (b) 800km neighbors
(tabN800.noele45 <- with (base[base$ele30==0,], prop.table (table (pbega, n800_d45_wequal_any), 2))*100)
(tabN800.noele90 <- with (base[base$ele30==0,], prop.table (table (pbega, n800_d90_wequal_any), 2))*100)
(tabN800.noele120 <- with (base[base$ele30==0,], prop.table (table (pbega, n800_d120_wequal_any), 2))*100)

(tabN800.noele45abs <- with (base[base$ele30==0,], table (pbega, n800_d45_wequal_any)))
(tabN800.noele90abs <- with (base[base$ele30==0,], table (pbega, n800_d90_wequal_any)))
(tabN800.noele120abs <- with (base[base$ele30==0,], table (pbega, n800_d120_wequal_any)))

# t-tests
(tvalN800.noele45 <- t.test (x=base[base$ele30==0 & base$n800_d45_wequal_any==0,]$pbega, y=base[base$ele30==0 & base$n800_d45_wequal_any==1,]$pbega))
(tvalN800.noele90 <- t.test (x=base[base$ele30==0 & base$n800_d90_wequal_any==0,]$pbega, y=base[base$ele30==0 & base$n800_d90_wequal_any==1,]$pbega))
(tvalN800.noele120 <- t.test (x=base[base$ele30==0 & base$n800_d120_wequal_any==0,]$pbega, y=base[base$ele30==0 & base$n800_d120_wequal_any==1,]$pbega))

# (c) UN region neighbors
(tabUNReg.noele45 <- with (base[base$ele30==0,], prop.table (table (pbega, nUN_d45_wequal_any), 2))*100)
(tabUNReg.noele90 <- with (base[base$ele30==0,], prop.table (table (pbega, nUN_d90_wequal_any), 2))*100)
(tabUNReg.noele120 <- with (base[base$ele30==0,], prop.table (table (pbega, nUN_d120_wequal_any), 2))*100)

(tabUNReg.noele45abs <- with (base[base$ele30==0,], table (pbega, nUN_d45_wequal_any)))
(tabUNReg.noele90abs <- with (base[base$ele30==0,], table (pbega, nUN_d90_wequal_any)))
(tabUNReg.noele120abs <- with (base[base$ele30==0,], table (pbega, nUN_d120_wequal_any)))

(tvalUNReg.noele45 <- t.test (x=base[base$ele30==0 & base$nUN_d45_wequal_any==0,]$pbega, y=base[base$ele30==0 & base$nUN_d45_wequal_any==1,]$pbega))
(tvalUNReg.noele90 <- t.test (x=base[base$ele30==0 & base$nUN_d90_wequal_any==0,]$pbega, y=base[base$ele30==0 & base$nUN_d90_wequal_any==1,]$pbega))
(tvalUNReg.noele120 <- t.test (x=base[base$ele30==0 & base$nUN_d120_wequal_any==0,]$pbega, y=base[base$ele30==0 & base$nUN_d120_wequal_any==1,]$pbega))


## (2.1.4) 1989 data

# (2.1.4.1) examining the data
colnames (base)[grep ("Size_", colnames (base))]
grep ("Size_", colnames (base))

base89 <- base[base$year==1989,1:max (grep ("Size_", colnames (base)))]
base89$id <- factor (base89$id)
base89$country <- factor (base89$country)
base89$region <- factor (base89$region)
base89$eeurope <- with (base89, ifelse (region=="East Europe", 1, 0))
base89$daysSpeech <- with (base89, as.numeric (date - as.Date ("1989-07-06")))  ## distance in days to Gorbachev's speech on Non-interference
base89$daysSpeech2 <- with (base89, ifelse (daysSpeech <= 0, 0, daysSpeech))/7 ## distance for days AFTER only, in weeks
base89$speech30 <- with (base89, ifelse (daysSpeech >= 1 & daysSpeech <= 30, 1, 0)) ## day within 30 days of speech
base89$speech45 <- with (base89, ifelse (daysSpeech >= 1 & daysSpeech <= 45, 1, 0))
base89$speech90 <- with (base89, ifelse (daysSpeech >= 1 & daysSpeech <= 90, 1, 0))
base89$speech120 <- with (base89, ifelse (daysSpeech >= 1 & daysSpeech <= 120, 1, 0))
base89$speech180 <- with (base89, ifelse (daysSpeech >= 1 & daysSpeech <= 180, 1, 0))
base89$cmonth <- NULL
base89$cweek <- NULL
base89$pbega2 <- base89$pbega * 100

## identifying neighbors
unique (base89[base89$region=="East Europe",c ("region", "country")])
# 187387  East Europe       Bulgaria
# 352204  East Europe Czechoslovakia
# 378795  East Europe   East Germany
# 550991  East Europe        Hungary
# 1013884 East Europe         Poland
# 1039084 East Europe        Romania
# 1159881 East Europe   Soviet Union

unique (base89[base89$country %in% c ("Albania", "Yugoslavia"),c ("region", "country")])
# 8361    South Europe    Albania
# 1394717 South Europe Yugoslavia

# distances data
distances <- read.dta13 ("Distances 1989-2011_tolerance0005.dta")
distances$mindist <- round (distances$mindist, 0)
summary (distances)

# Bulgaria
sort (distances[distances$year==1989 & distances$mindist <= 50 & distances$country=="Bulgaria" & distances$country2!="Bulgaria","country2"])
sort (distances[distances$year==1989 & distances$mindist > 50 & distances$mindist <= 800 & distances$country=="Bulgaria" & distances$country2!="Bulgaria","country2"])

# Czechoslovakia
sort (distances[distances$year==1989 & distances$mindist <= 50 & distances$country=="Czechoslovakia" & distances$country2!="Czechoslovakia","country2"])
sort (distances[distances$year==1989 & distances$mindist > 50 & distances$mindist <= 800 & distances$country=="Czechoslovakia" & distances$country2!="Czechoslovakia","country2"])

# East Germany
sort (distances[distances$year==1989 & distances$mindist <= 50 & distances$country=="East Germany" & distances$country2!="East Germany","country2"])
sort (distances[distances$year==1989 & distances$mindist > 50 & distances$mindist <= 800 & distances$country=="East Germany" & distances$country2!="East Germany","country2"])

# Hungary
sort (distances[distances$year==1989 & distances$mindist <= 50 & distances$country=="Hungary" & distances$country2!="Hungary","country2"])
sort (distances[distances$year==1989 & distances$mindist > 50 & distances$mindist <= 800 & distances$country=="Hungary" & distances$country2!="Hungary","country2"])

# Poland
sort (distances[distances$year==1989 & distances$mindist <= 50 & distances$country=="Poland" & distances$country2!="Poland","country2"])
sort (distances[distances$year==1989 & distances$mindist > 50 & distances$mindist <= 800 & distances$country=="Poland" & distances$country2!="Poland","country2"])

# Romania
sort (distances[distances$year==1989 & distances$mindist <= 50 & distances$country=="Romania" & distances$country2!="Romania","country2"])
sort (distances[distances$year==1989 & distances$mindist > 50 & distances$mindist <= 800 & distances$country=="Romania" & distances$country2!="Romania","country2"])

# Soviet Union
sort (distances[distances$year==1989 & distances$mindist <= 50 & distances$country=="Soviet Union" & distances$country2!="Soviet Union","country2"])
sort (distances[distances$year==1989 & distances$mindist > 50 & distances$mindist <= 800 & distances$country=="Soviet Union" & distances$country2!="Soviet Union","country2"])

# some descriptive statistics
nrow (base89)  ## 55,164 observations
length (unique (base89$country))  ## 152 countries
sum (base89$pbega)  ## 15 democracy protests in all


# (2.1.4.2) Replicating the data reported in Table A50: Data Overview: 1989

# (a) contiguous neighbors
(t89Cont30 <- with (base89, prop.table (table (pbega, n50_d30_wequal_any), 2))*100)
(t89Cont45 <- with (base89, prop.table (table (pbega, n50_d45_wequal_any), 2))*100)
(t89Cont90 <- with (base89, prop.table (table (pbega, n50_d90_wequal_any), 2))*100)
(t89Cont120 <- with (base89, prop.table (table (pbega, n50_d120_wequal_any), 2))*100)

(t89Cont30abs <- with (base89, table (pbega, n50_d30_wequal_any)))
(t89Cont45abs <- with (base89, table (pbega, n50_d45_wequal_any)))
(t89Cont90abs <- with (base89, table (pbega, n50_d90_wequal_any)))
(t89Cont120abs <- with (base89, table (pbega, n50_d120_wequal_any)))

# t-tests
(tval89Cont30 <- t.test (x=base89[base89$n50_d30_wequal_any==0,]$pbega, y=base89[base89$n50_d30_wequal_any==1,]$pbega))
(tval89Cont45 <- t.test (x=base89[base89$n50_d45_wequal_any==0,]$pbega, y=base89[base89$n50_d45_wequal_any==1,]$pbega))
(tval89Cont90 <- t.test (x=base89[base89$n50_d90_wequal_any==0,]$pbega, y=base89[base89$n50_d90_wequal_any==1,]$pbega))
(tval89Cont120 <- t.test (x=base89[base89$n50_d120_wequal_any==0,]$pbega, y=base89[base89$n50_d120_wequal_any==1,]$pbega))

# (b) 800km neighbors
(t89N800.30 <- with (base89, prop.table (table (pbega, n800_d30_wequal_any), 2))*100)
(t89N800.45 <- with (base89, prop.table (table (pbega, n800_d45_wequal_any), 2))*100)
(t89N800.90 <- with (base89, prop.table (table (pbega, n800_d90_wequal_any), 2))*100)
(t89N800.120 <- with (base89, prop.table (table (pbega, n800_d120_wequal_any), 2))*100)

(t89N800.30abs <- with (base89, table (pbega, n800_d30_wequal_any)))
(t89N800.45abs <- with (base89, table (pbega, n800_d45_wequal_any)))
(t89N800.90abs <- with (base89, table (pbega, n800_d90_wequal_any)))
(t89N800.120abs <- with (base89, table (pbega, n800_d120_wequal_any)))

# t-tests
(tval89N800.30 <- t.test (x=base89[base89$n800_d30_wequal_any==0,]$pbega, y=base89[base89$n800_d30_wequal_any==1,]$pbega))
(tval89N800.45 <- t.test (x=base89[base89$n800_d45_wequal_any==0,]$pbega, y=base89[base89$n800_d45_wequal_any==1,]$pbega))
(tval89N800.90 <- t.test (x=base89[base89$n800_d90_wequal_any==0,]$pbega, y=base89[base89$n800_d90_wequal_any==1,]$pbega))
(tval89N800.120 <- t.test (x=base89[base89$n800_d120_wequal_any==0,]$pbega, y=base89[base89$n800_d120_wequal_any==1,]$pbega))

# (c) UN region neighbors
(t89UNReg30 <- with (base89, prop.table (table (pbega, nUN_d30_wequal_any), 2))*100)
(t89UNReg45 <- with (base89, prop.table (table (pbega, nUN_d45_wequal_any), 2))*100)
(t89UNReg90 <- with (base89, prop.table (table (pbega, nUN_d90_wequal_any), 2))*100)
(t89UNReg120 <- with (base89, prop.table (table (pbega, nUN_d120_wequal_any), 2))*100)

(t89UNReg30abs <- with (base89, table (pbega, nUN_d30_wequal_any)))
(t89UNReg45abs <- with (base89, table (pbega, nUN_d45_wequal_any)))
(t89UNReg90abs <- with (base89, table (pbega, nUN_d90_wequal_any)))
(t89UNReg120abs <- with (base89, table (pbega, nUN_d120_wequal_any)))

# t-tests
(tval89UNReg30 <- t.test (x=base89[base89$nUN_d30_wequal_any==0,]$pbega, y=base89[base89$nUN_d30_wequal_any==1,]$pbega))
(tval89UNReg45 <- t.test (x=base89[base89$nUN_d45_wequal_any==0,]$pbega, y=base89[base89$nUN_d45_wequal_any==1,]$pbega))
(tval89UNReg90 <- t.test (x=base89[base89$nUN_d90_wequal_any==0,]$pbega, y=base89[base89$nUN_d90_wequal_any==1,]$pbega))
(tval89UNReg120 <- t.test (x=base89[base89$nUN_d120_wequal_any==0,]$pbega, y=base89[base89$nUN_d120_wequal_any==1,]$pbega))


## (2.1.5) 2011 data

# (2.1.5.1) examining the data

# 2011, from the full dataset
base11 <- base[base$year==2011,1:max (grep ("Size_", colnames (base)))]
base11$id <- factor (base11$id)
base11$country <- factor (base11$country)
base11$region <- factor (base11$region)
base11$cmonth <- NULL
base11$cweek <- NULL
base11$pbega2 <- base11$pbega * 100

## identifying neighbors
unique (base11[base11$region %in% c ("North Africa", "West Asia"),c ("region", "country")])  ## 23 countries
# 24696   North Africa              Algeria
# 48751      West Asia              Armenia
# 72662      West Asia           Azerbaijan
# 88936      West Asia              Bahrain
# 344900     West Asia               Cyprus
# 395443  North Africa                Egypt
# 475700     West Asia              Georgia
# 600681     West Asia                 Iraq
# 617478     West Asia               Israel
# 659186     West Asia               Jordan
# 684483     West Asia               Kuwait
# 715894     West Asia              Lebanon
# 740977  North Africa                Libya
# 864537  North Africa              Morocco
# 963543     West Asia                 Oman
# 1038719    West Asia                Qatar
# 1079584    West Asia         Saudi Arabia
# 1185700 North Africa                Sudan
# 1227671    West Asia                Syria
# 1296675 North Africa              Tunisia
# 1305071    West Asia               Turkey
# 1336460    West Asia United Arab Emirates
# 1394661    West Asia                Yemen

# some descriptive statistics
nrow (base11)  ## 62,720 observations
length (unique (base11$country))  ## 175 countries
sum (base11$pbega)  ## 25 democracy protests in all

# 2011 only (including additional protests in Tunisia, Syria and Libya)
bspring11 <- bspring[bspring$year==2011,1:max (grep ("Size_", colnames (bspring)))]
bspring11$country <- factor (bspring11$country)
bspring11$region <- factor (bspring11$region)
bspring11$id <- with (bspring11, factor (paste (country, date, sep="_")))
bspring11$pbega2 <- bspring11$pbega * 100

# some descriptive statistics
nrow (bspring11)  ## 62,539 observations
length (unique (bspring11$country))  ## 175 countries
sum (bspring11$pbega)  ## 27 democracy protests in all


# (2.1.5.2) Replicating the data reported in Table A54: Data Overview: 2011

# (2.1.5.2.1) Overview of the data (from full sample)

# (a) contiguous neighbors
(t11Cont30 <- with (base11, prop.table (table (pbega, n50_d30_wequal_any), 2))*100)
(t11Cont45 <- with (base11, prop.table (table (pbega, n50_d45_wequal_any), 2))*100)
(t11Cont90 <- with (base11, prop.table (table (pbega, n50_d90_wequal_any), 2))*100)
(t11Cont120 <- with (base11, prop.table (table (pbega, n50_d120_wequal_any), 2))*100)

(t11Cont30abs <- with (base11, table (pbega, n50_d30_wequal_any)))
(t11Cont45abs <- with (base11, table (pbega, n50_d45_wequal_any)))
(t11Cont90abs <- with (base11, table (pbega, n50_d90_wequal_any)))
(t11Cont120abs <- with (base11, table (pbega, n50_d120_wequal_any)))

# t-tests
(tval11Cont30 <- t.test (x=base11[base11$n50_d30_wequal_any==0,]$pbega, y=base11[base11$n50_d30_wequal_any==1,]$pbega))
(tval11Cont45 <- t.test (x=base11[base11$n50_d45_wequal_any==0,]$pbega, y=base11[base11$n50_d45_wequal_any==1,]$pbega))
(tval11Cont90 <- t.test (x=base11[base11$n50_d90_wequal_any==0,]$pbega, y=base11[base11$n50_d90_wequal_any==1,]$pbega))
(tval11Cont120 <- t.test (x=base11[base11$n50_d120_wequal_any==0,]$pbega, y=base11[base11$n50_d120_wequal_any==1,]$pbega))

# (b) 800km neighbors
(t11N800.30 <- with (base11, prop.table (table (pbega, n800_d30_wequal_any), 2))*100)
(t11N800.45 <- with (base11, prop.table (table (pbega, n800_d45_wequal_any), 2))*100)
(t11N800.90 <- with (base11, prop.table (table (pbega, n800_d90_wequal_any), 2))*100)
(t11N800.120 <- with (base11, prop.table (table (pbega, n800_d120_wequal_any), 2))*100)

(t11N800.30abs <- with (base11, table (pbega, n800_d30_wequal_any)))
(t11N800.45abs <- with (base11, table (pbega, n800_d45_wequal_any)))
(t11N800.90abs <- with (base11, table (pbega, n800_d90_wequal_any)))
(t11N800.120abs <- with (base11, table (pbega, n800_d120_wequal_any)))

# t-tests
(tval11N800.30 <- t.test (x=base11[base11$n800_d30_wequal_any==0,]$pbega, y=base11[base11$n800_d30_wequal_any==1,]$pbega))
(tval11N800.45 <- t.test (x=base11[base11$n800_d45_wequal_any==0,]$pbega, y=base11[base11$n800_d45_wequal_any==1,]$pbega))
(tval11N800.90 <- t.test (x=base11[base11$n800_d90_wequal_any==0,]$pbega, y=base11[base11$n800_d90_wequal_any==1,]$pbega))
(tval11N800.120 <- t.test (x=base11[base11$n800_d120_wequal_any==0,]$pbega, y=base11[base11$n800_d120_wequal_any==1,]$pbega))

# (c) same UN region
(t11UNReg30 <- with (base11, prop.table (table (pbega, nUN_d30_wequal_any), 2))*100)
(t11UNReg45 <- with (base11, prop.table (table (pbega, nUN_d45_wequal_any), 2))*100)
(t11UNReg90 <- with (base11, prop.table (table (pbega, nUN_d90_wequal_any), 2))*100)
(t11UNReg120 <- with (base11, prop.table (table (pbega, nUN_d120_wequal_any), 2))*100)

(t11UNReg30abs <- with (base11, table (pbega, nUN_d30_wequal_any)))
(t11UNReg45abs <- with (base11, table (pbega, nUN_d45_wequal_any)))
(t11UNReg90abs <- with (base11, table (pbega, nUN_d90_wequal_any)))
(t11UNReg120abs <- with (base11, table (pbega, nUN_d120_wequal_any)))

# t-tests
(tval11UNReg30 <- t.test (x=base11[base11$nUN_d30_wequal_any==0,]$pbega, y=base11[base11$nUN_d30_wequal_any==1,]$pbega))
(tval11UNReg45 <- t.test (x=base11[base11$nUN_d45_wequal_any==0,]$pbega, y=base11[base11$nUN_d45_wequal_any==1,]$pbega))
(tval11UNReg90 <- t.test (x=base11[base11$nUN_d90_wequal_any==0,]$pbega, y=base11[base11$nUN_d90_wequal_any==1,]$pbega))
(tval11UNReg120 <- t.test (x=base11[base11$nUN_d120_wequal_any==0,]$pbega, y=base11[base11$nUN_d120_wequal_any==1,]$pbega))

# (2.1.5.2.2) Overview of the data (Arab Spring data)

# (a) contiguous neighbors
(tspringCont30 <- with (bspring11, prop.table (table (pbega, n50_d30_wequal_any), 2))*100)
(tspringCont45 <- with (bspring11, prop.table (table (pbega, n50_d45_wequal_any), 2))*100)
(tspringCont90 <- with (bspring11, prop.table (table (pbega, n50_d90_wequal_any), 2))*100)
(tspringCont120 <- with (bspring11, prop.table (table (pbega, n50_d120_wequal_any), 2))*100)

(tspringCont30abs <- with (bspring11, table (pbega, n50_d30_wequal_any)))
(tspringCont45abs <- with (bspring11, table (pbega, n50_d45_wequal_any)))
(tspringCont90abs <- with (bspring11, table (pbega, n50_d90_wequal_any)))
(tspringCont120abs <- with (bspring11, table (pbega, n50_d120_wequal_any)))

# t-tests
(tvalSpringCont30 <- t.test (x=bspring11[bspring11$n50_d30_wequal_any==0,]$pbega, y=bspring11[bspring11$n50_d30_wequal_any==1,]$pbega))
(tvalSpringCont45 <- t.test (x=bspring11[bspring11$n50_d45_wequal_any==0,]$pbega, y=bspring11[bspring11$n50_d45_wequal_any==1,]$pbega))
(tvalSpringCont90 <- t.test (x=bspring11[bspring11$n50_d90_wequal_any==0,]$pbega, y=bspring11[bspring11$n50_d90_wequal_any==1,]$pbega))
(tvalSpringCont120 <- t.test (x=bspring11[bspring11$n50_d120_wequal_any==0,]$pbega, y=bspring11[bspring11$n50_d120_wequal_any==1,]$pbega))

# (b) 800km neighbors
(tspringN800.30 <- with (bspring11, prop.table (table (pbega, n800_d30_wequal_any), 2))*100)
(tspringN800.45 <- with (bspring11, prop.table (table (pbega, n800_d45_wequal_any), 2))*100)
(tspringN800.90 <- with (bspring11, prop.table (table (pbega, n800_d90_wequal_any), 2))*100)
(tspringN800.120 <- with (bspring11, prop.table (table (pbega, n800_d120_wequal_any), 2))*100)

(tspringN800.30abs <- with (bspring11, table (pbega, n800_d30_wequal_any)))
(tspringN800.45abs <- with (bspring11, table (pbega, n800_d45_wequal_any)))
(tspringN800.90abs <- with (bspring11, table (pbega, n800_d90_wequal_any)))
(tspringN800.120abs <- with (bspring11, table (pbega, n800_d120_wequal_any)))

# t-tests
(tvalSpringN800.30 <- t.test (x=bspring11[bspring11$n800_d30_wequal_any==0,]$pbega, y=bspring11[bspring11$n800_d30_wequal_any==1,]$pbega))
(tvalSpringN800.45 <- t.test (x=bspring11[bspring11$n800_d45_wequal_any==0,]$pbega, y=bspring11[bspring11$n800_d45_wequal_any==1,]$pbega))
(tvalSpringN800.90 <- t.test (x=bspring11[bspring11$n800_d90_wequal_any==0,]$pbega, y=bspring11[bspring11$n800_d90_wequal_any==1,]$pbega))
(tvalSpringN800.120 <- t.test (x=bspring11[bspring11$n800_d120_wequal_any==0,]$pbega, y=bspring11[bspring11$n800_d120_wequal_any==1,]$pbega))

# (c) same UN region
(tspringUNReg30 <- with (bspring11, prop.table (table (pbega, nUN_d30_wequal_any), 2))*100)
(tspringUNReg45 <- with (bspring11, prop.table (table (pbega, nUN_d45_wequal_any), 2))*100)
(tspringUNReg90 <- with (bspring11, prop.table (table (pbega, nUN_d90_wequal_any), 2))*100)
(tspringUNReg120 <- with (bspring11, prop.table (table (pbega, nUN_d120_wequal_any), 2))*100)

(tspringUNReg30abs <- with (bspring11, table (pbega, nUN_d30_wequal_any)))
(tspringUNReg45abs <- with (bspring11, table (pbega, nUN_d45_wequal_any)))
(tspringUNReg90abs <- with (bspring11, table (pbega, nUN_d90_wequal_any)))
(tspringUNReg120abs <- with (bspring11, table (pbega, nUN_d120_wequal_any)))

# t-tests
(tvalSpringUNReg30 <- t.test (x=bspring11[bspring11$nUN_d30_wequal_any==0,]$pbega, y=bspring11[bspring11$nUN_d30_wequal_any==1,]$pbega))
(tvalSpringUNReg45 <- t.test (x=bspring11[bspring11$nUN_d45_wequal_any==0,]$pbega, y=bspring11[bspring11$nUN_d45_wequal_any==1,]$pbega))
(tvalSpringUNReg90 <- t.test (x=bspring11[bspring11$nUN_d90_wequal_any==0,]$pbega, y=bspring11[bspring11$nUN_d90_wequal_any==1,]$pbega))
(tvalSpringUNReg120 <- t.test (x=bspring11[bspring11$nUN_d120_wequal_any==0,]$pbega, y=bspring11[bspring11$nUN_d120_wequal_any==1,]$pbega))

# (2.1.5.2.3) Overview of the data (MENA-only sample)

# (a) contiguous neighbors
(tmenaCont30 <- with (bmena, prop.table (table (pbega, n50_d30_wequal_any), 2))*100)
(tmenaCont45 <- with (bmena, prop.table (table (pbega, n50_d45_wequal_any), 2))*100)
(tmenaCont90 <- with (bmena, prop.table (table (pbega, n50_d90_wequal_any), 2))*100)
(tmenaCont120 <- with (bmena, prop.table (table (pbega, n50_d120_wequal_any), 2))*100)

(tmenaCont30abs <- with (bmena, table (pbega, n50_d30_wequal_any)))
(tmenaCont45abs <- with (bmena, table (pbega, n50_d45_wequal_any)))
(tmenaCont90abs <- with (bmena, table (pbega, n50_d90_wequal_any)))
(tmenaCont120abs <- with (bmena, table (pbega, n50_d120_wequal_any)))

# t-tests
(tvalMENACont30 <- t.test (x=bmena[bmena$n50_d30_wequal_any==0,]$pbega, y=bmena[bmena$n50_d30_wequal_any==1,]$pbega))
(tvalMENACont45 <- t.test (x=bmena[bmena$n50_d45_wequal_any==0,]$pbega, y=bmena[bmena$n50_d45_wequal_any==1,]$pbega))
(tvalMENACont90 <- t.test (x=bmena[bmena$n50_d90_wequal_any==0,]$pbega, y=bmena[bmena$n50_d90_wequal_any==1,]$pbega))
(tvalMENACont120 <- t.test (x=bmena[bmena$n50_d120_wequal_any==0,]$pbega, y=bmena[bmena$n50_d120_wequal_any==1,]$pbega))

# (b) 800km neighbors
(tmenaN800.30 <- with (bmena, prop.table (table (pbega, n800_d30_wequal_any), 2))*100)
(tmenaN800.45 <- with (bmena, prop.table (table (pbega, n800_d45_wequal_any), 2))*100)
(tmenaN800.90 <- with (bmena, prop.table (table (pbega, n800_d90_wequal_any), 2))*100)
(tmenaN800.120 <- with (bmena, prop.table (table (pbega, n800_d120_wequal_any), 2))*100)

(tmenaN800.30abs <- with (bmena, table (pbega, n800_d30_wequal_any)))
(tmenaN800.45abs <- with (bmena, table (pbega, n800_d45_wequal_any)))
(tmenaN800.90abs <- with (bmena, table (pbega, n800_d90_wequal_any)))
(tmenaN800.120abs <- with (bmena, table (pbega, n800_d120_wequal_any)))

# t-tests
(tvalMENAN800.30 <- t.test (x=bmena[bmena$n800_d30_wequal_any==0,]$pbega, y=bmena[bmena$n800_d30_wequal_any==1,]$pbega))
(tvalMENAN800.45 <- t.test (x=bmena[bmena$n800_d45_wequal_any==0,]$pbega, y=bmena[bmena$n800_d45_wequal_any==1,]$pbega))
(tvalMENAN800.90 <- t.test (x=bmena[bmena$n800_d90_wequal_any==0,]$pbega, y=bmena[bmena$n800_d90_wequal_any==1,]$pbega))
(tvalMENAN800.120 <- t.test (x=bmena[bmena$n800_d120_wequal_any==0,]$pbega, y=bmena[bmena$n800_d120_wequal_any==1,]$pbega))

# (c) UN regions
(tmenaUNReg30 <- with (bmena, prop.table (table (pbega, nUN_d30_wequal_any), 2))*100)
(tmenaUNReg45 <- with (bmena, prop.table (table (pbega, nUN_d45_wequal_any), 2))*100)
(tmenaUNReg90 <- with (bmena, prop.table (table (pbega, nUN_d90_wequal_any), 2))*100)
(tmenaUNReg120 <- with (bmena, prop.table (table (pbega, nUN_d120_wequal_any), 2))*100)

(tmenaUNReg30abs <- with (bmena, table (pbega, nUN_d30_wequal_any)))
(tmenaUNReg45abs <- with (bmena, table (pbega, nUN_d45_wequal_any)))
(tmenaUNReg90abs <- with (bmena, table (pbega, nUN_d90_wequal_any)))
(tmenaUNReg120abs <- with (bmena, table (pbega, nUN_d120_wequal_any)))

# t-tests
(tvalMENAUNReg30 <- t.test (x=bmena[bmena$nUN_d30_wequal_any==0,]$pbega, y=bmena[bmena$nUN_d30_wequal_any==1,]$pbega))
(tvalMENAUNReg45 <- t.test (x=bmena[bmena$nUN_d45_wequal_any==0,]$pbega, y=bmena[bmena$nUN_d45_wequal_any==1,]$pbega))
(tvalMENAUNReg90 <- t.test (x=bmena[bmena$nUN_d90_wequal_any==0,]$pbega, y=bmena[bmena$nUN_d90_wequal_any==1,]$pbega))
(tvalMENAUNReg120 <- t.test (x=bmena[bmena$nUN_d120_wequal_any==0,]$pbega, y=bmena[bmena$nUN_d120_wequal_any==1,]$pbega))

# (2.1.5.2.4) Overview of the data (MENA-only sample, 2011)
bmena11 <- bmena[bmena$year==2011,1:max (grep ("Size_", colnames (bmena)))]
bmena11$country <- factor (bmena11$country)
bmena11$region <- factor (bmena11$region)
bmena11$id <- with (bmena11, factor (paste (country, date, sep="_")))
bmena11$pbega2 <- bmena11$pbega * 100

# some descriptive statistics
nrow (bmena11)  ## 6,284 observations
length (unique (bmena11$country))  ## 20 countries
sum (bmena11$pbega)  ## 9 democracy protests in all

# (a) contiguous neighbors
(tmena11Cont30 <- with (bmena11, prop.table (table (pbega, n50_d30_wequal_any), 2))*100)
(tmena11Cont45 <- with (bmena11, prop.table (table (pbega, n50_d45_wequal_any), 2))*100)
(tmena11Cont90 <- with (bmena11, prop.table (table (pbega, n50_d90_wequal_any), 2))*100)
(tmena11Cont120 <- with (bmena11, prop.table (table (pbega, n50_d120_wequal_any), 2))*100)

(tmena11Cont30abs <- with (bmena11, table (pbega, n50_d30_wequal_any)))
(tmena11Cont45abs <- with (bmena11, table (pbega, n50_d45_wequal_any)))
(tmena11Cont90abs <- with (bmena11, table (pbega, n50_d90_wequal_any)))
(tmena11Cont120abs <- with (bmena11, table (pbega, n50_d120_wequal_any)))

# t-tests
(tvalMENA11Cont30 <- t.test (x=bmena11[bmena11$n50_d30_wequal_any==0,]$pbega, y=bmena11[bmena11$n50_d30_wequal_any==1,]$pbega))
(tvalMENA11Cont45 <- t.test (x=bmena11[bmena11$n50_d45_wequal_any==0,]$pbega, y=bmena11[bmena11$n50_d45_wequal_any==1,]$pbega))
(tvalMENA11Cont90 <- t.test (x=bmena11[bmena11$n50_d90_wequal_any==0,]$pbega, y=bmena11[bmena11$n50_d90_wequal_any==1,]$pbega))
(tvalMENA11Cont120 <- t.test (x=bmena11[bmena11$n50_d120_wequal_any==0,]$pbega, y=bmena11[bmena11$n50_d120_wequal_any==1,]$pbega))

# (b) 800km neighbors
(tmena11N800.30 <- with (bmena11, prop.table (table (pbega, n800_d30_wequal_any), 2))*100)
(tmena11N800.45 <- with (bmena11, prop.table (table (pbega, n800_d45_wequal_any), 2))*100)
(tmena11N800.90 <- with (bmena11, prop.table (table (pbega, n800_d90_wequal_any), 2))*100)
(tmena11N800.120 <- with (bmena11, prop.table (table (pbega, n800_d120_wequal_any), 2))*100)

(tmena11N800.30abs <- with (bmena11, table (pbega, n800_d30_wequal_any)))
(tmena11N800.45abs <- with (bmena11, table (pbega, n800_d45_wequal_any)))
(tmena11N800.90abs <- with (bmena11, table (pbega, n800_d90_wequal_any)))
(tmena11N800.120abs <- with (bmena11, table (pbega, n800_d120_wequal_any)))

# t-tests
(tvalMENA11N800.30 <- t.test (x=bmena11[bmena11$n800_d30_wequal_any==0,]$pbega, y=bmena11[bmena11$n800_d30_wequal_any==1,]$pbega))
(tvalMENA11N800.45 <- t.test (x=bmena11[bmena11$n800_d45_wequal_any==0,]$pbega, y=bmena11[bmena11$n800_d45_wequal_any==1,]$pbega))
(tvalMENA11N800.90 <- t.test (x=bmena11[bmena11$n800_d90_wequal_any==0,]$pbega, y=bmena11[bmena11$n800_d90_wequal_any==1,]$pbega))
(tvalMENA11N800.120 <- t.test (x=bmena11[bmena11$n800_d120_wequal_any==0,]$pbega, y=bmena11[bmena11$n800_d120_wequal_any==1,]$pbega))

# (c) UN regions -> cannot do any analysis because all countries are neighbors, and there had been SOME country with democracy protests within the last 30, 45, 90 or 120 days for practically the entire year
(tmena11UNReg30 <- with (bmena11, prop.table (table (pbega, nUN_d30_wequal_any), 2))*100)
(tmena11UNReg45 <- with (bmena11, prop.table (table (pbega, nUN_d45_wequal_any), 2))*100)
(tmena11UNReg90 <- with (bmena11, prop.table (table (pbega, nUN_d90_wequal_any), 2))*100)
(tmena11UNReg120 <- with (bmena11, prop.table (table (pbega, nUN_d120_wequal_any), 2))*100)

(tmena11UNReg30abs <- with (bmena11, table (pbega, nUN_d30_wequal_any)))
(tmena11UNReg45abs <- with (bmena11, table (pbega, nUN_d45_wequal_any)))
(tmena11UNReg90abs <- with (bmena11, table (pbega, nUN_d90_wequal_any)))
(tmena11UNReg120abs <- with (bmena11, table (pbega, nUN_d120_wequal_any)))

# t-tests
(tvalMENA11UNReg30 <- t.test (x=bmena11[bmena11$nUN_d30_wequal_any==0,]$pbega, y=bmena11[bmena11$nUN_d30_wequal_any==1,]$pbega))
(tvalMENA11UNReg45 <- t.test (x=bmena11[bmena11$nUN_d45_wequal_any==0,]$pbega, y=bmena11[bmena11$nUN_d45_wequal_any==1,]$pbega))
(tvalMENA11UNReg90 <- t.test (x=bmena11[bmena11$nUN_d90_wequal_any==0,]$pbega, y=bmena11[bmena11$nUN_d90_wequal_any==1,]$pbega))
(tvalMENA11UNReg120 <- t.test (x=bmena11[bmena11$nUN_d120_wequal_any==0,]$pbega, y=bmena11[bmena11$nUN_d120_wequal_any==1,]$pbega))


## (2.1.6) Replicating values in Table A66: % of observations with zeroes

# 50-km neighbors
(pct50a_gdp <- round (nrow (base[!is.na (base$n50_d45_wrelAbsGDPcap_any) & base$n50_d45_wrelAbsGDPcap_any==0,]) / nrow (base[!is.na (base$n50_d45_wrelAbsGDPcap_any),])*100,2))
(pct50a_gdp2 <- round (nrow (base[!is.na (base$n50_d45_wrelAbsGDPcap_any) & base$n50_d45_wequal_any==0,]) / nrow (base[!is.na (base$n50_d45_wrelAbsGDPcap_any),])*100,2))
(pct50b_gdp <- round (nrow (base[!is.na (base$n50_d90_wrelAbsGDPcap_any) & base$n50_d90_wrelAbsGDPcap_any==0,]) / nrow (base[!is.na (base$n50_d90_wrelAbsGDPcap_any),])*100,2))
(pct50b_gdp2 <- round (nrow (base[!is.na (base$n50_d90_wrelAbsGDPcap_any) & base$n50_d90_wequal_any==0,]) / nrow (base[!is.na (base$n50_d90_wrelAbsGDPcap_any),])*100,2))
(pct50c_gdp <- round (nrow (base[!is.na (base$n50_d120_wrelAbsGDPcap_any) & base$n50_d120_wrelAbsGDPcap_any==0,]) / nrow (base[!is.na (base$n50_d120_wrelAbsGDPcap_any),])*100,2))
(pct50c_gdp2 <- round (nrow (base[!is.na (base$n50_d120_wrelAbsGDPcap_any) & base$n50_d120_wequal_any==0,]) / nrow (base[!is.na (base$n50_d120_wrelAbsGDPcap_any),])*100,2))

(pct50a_pop <- round (nrow (base[!is.na (base$n50_d45_wrelAbsPop_any) & base$n50_d45_wrelAbsPop_any==0,]) / nrow (base[!is.na (base$n50_d45_wrelAbsPop_any),])*100,2))
(pct50a_pop2 <- round (nrow (base[!is.na (base$n50_d45_wrelAbsPop_any) & base$n50_d45_wequal_any==0,]) / nrow (base[!is.na (base$n50_d45_wrelAbsPop_any),])*100,2))
(pct50b_pop <- round (nrow (base[!is.na (base$n50_d90_wrelAbsPop_any) & base$n50_d90_wrelAbsPop_any==0,]) / nrow (base[!is.na (base$n50_d90_wrelAbsPop_any),])*100,2))
(pct50b_pop2 <- round (nrow (base[!is.na (base$n50_d90_wrelAbsPop_any) & base$n50_d90_wequal_any==0,]) / nrow (base[!is.na (base$n50_d90_wrelAbsPop_any),])*100,2))
(pct50c_pop <- round (nrow (base[!is.na (base$n50_d120_wrelAbsPop_any) & base$n50_d120_wrelAbsPop_any==0,]) / nrow (base[!is.na (base$n50_d120_wrelAbsPop_any),])*100,2))
(pct50c_pop2 <- round (nrow (base[!is.na (base$n50_d120_wrelAbsPop_any) & base$n50_d120_wequal_any==0,]) / nrow (base[!is.na (base$n50_d120_wrelAbsPop_any),])*100,2))

(pct50a_repr <- round (nrow (base[!is.na (base$n50_d45_wrelAbsRepr_any) & base$n50_d45_wrelAbsRepr_any==0,]) / nrow (base[!is.na (base$n50_d45_wrelAbsRepr_any),])*100,2))
(pct50a_repr2 <- round (nrow (base[!is.na (base$n50_d45_wrelAbsRepr_any) & base$n50_d45_wequal_any==0,]) / nrow (base[!is.na (base$n50_d45_wrelAbsRepr_any),])*100,2))
(pct50b_repr <- round (nrow (base[!is.na (base$n50_d90_wrelAbsRepr_any) & base$n50_d90_wrelAbsRepr_any==0,]) / nrow (base[!is.na (base$n50_d90_wrelAbsRepr_any),])*100,2))
(pct50b_repr2 <- round (nrow (base[!is.na (base$n50_d90_wrelAbsRepr_any) & base$n50_d90_wequal_any==0,]) / nrow (base[!is.na (base$n50_d90_wrelAbsRepr_any),])*100,2))
(pct50c_repr <- round (nrow (base[!is.na (base$n50_d120_wrelAbsRepr_any) & base$n50_d120_wrelAbsRepr_any==0,]) / nrow (base[!is.na (base$n50_d120_wrelAbsRepr_any),])*100,2))
(pct50c_repr2 <- round (nrow (base[!is.na (base$n50_d120_wrelAbsRepr_any) & base$n50_d120_wequal_any==0,]) / nrow (base[!is.na (base$n50_d120_wrelAbsRepr_any),])*100,2))

(pct50a_piv <- round (nrow (base[!is.na (base$n50_d45_wrelAbsPolity_any) & base$n50_d45_wrelAbsPolity_any==0,]) / nrow (base[!is.na (base$n50_d45_wrelAbsPolity_any),])*100,2))
(pct50a_piv2 <- round (nrow (base[!is.na (base$n50_d45_wrelAbsPolity_any) & base$n50_d45_wequal_any==0,]) / nrow (base[!is.na (base$n50_d45_wrelAbsPolity_any),])*100,2))
(pct50b_piv <- round (nrow (base[!is.na (base$n50_d90_wrelAbsPolity_any) & base$n50_d90_wrelAbsPolity_any==0,]) / nrow (base[!is.na (base$n50_d90_wrelAbsPolity_any),])*100,2))
(pct50b_piv2 <- round (nrow (base[!is.na (base$n50_d90_wrelAbsPolity_any) & base$n50_d90_wequal_any==0,]) / nrow (base[!is.na (base$n50_d90_wrelAbsPolity_any),])*100,2))
(pct50c_piv <- round (nrow (base[!is.na (base$n50_d120_wrelAbsPolity_any) & base$n50_d120_wrelAbsPolity_any==0,]) / nrow (base[!is.na (base$n50_d120_wrelAbsPolity_any),])*100,2))
(pct50c_piv2 <- round (nrow (base[!is.na (base$n50_d120_wrelAbsPolity_any) & base$n50_d120_wequal_any==0,]) / nrow (base[!is.na (base$n50_d120_wrelAbsPolity_any),])*100,2))

# 800km neighbors
(pct800a_gdp <- round (nrow (base[!is.na (base$n800_d45_wrelAbsGDPcap_any) & base$n800_d45_wrelAbsGDPcap_any==0,]) / nrow (base[!is.na (base$n800_d45_wrelAbsGDPcap_any),])*100,2))
(pct800a_gdp2 <- round (nrow (base[!is.na (base$n800_d45_wrelAbsGDPcap_any) & base$n800_d45_wequal_any==0,]) / nrow (base[!is.na (base$n800_d45_wrelAbsGDPcap_any),])*100,2))
(pct800b_gdp <- round (nrow (base[!is.na (base$n800_d90_wrelAbsGDPcap_any) & base$n800_d90_wrelAbsGDPcap_any==0,]) / nrow (base[!is.na (base$n800_d90_wrelAbsGDPcap_any),])*100,2))
(pct800b_gdp2 <- round (nrow (base[!is.na (base$n800_d90_wrelAbsGDPcap_any) & base$n800_d90_wequal_any==0,]) / nrow (base[!is.na (base$n800_d90_wrelAbsGDPcap_any),])*100,2))
(pct800c_gdp <- round (nrow (base[!is.na (base$n800_d120_wrelAbsGDPcap_any) & base$n800_d120_wrelAbsGDPcap_any==0,]) / nrow (base[!is.na (base$n800_d120_wrelAbsGDPcap_any),])*100,2))
(pct800c_gdp2 <- round (nrow (base[!is.na (base$n800_d120_wrelAbsGDPcap_any) & base$n800_d120_wequal_any==0,]) / nrow (base[!is.na (base$n800_d120_wrelAbsGDPcap_any),])*100,2))

(pct800a_pop <- round (nrow (base[!is.na (base$n800_d45_wrelAbsPop_any) & base$n800_d45_wrelAbsPop_any==0,]) / nrow (base[!is.na (base$n800_d45_wrelAbsPop_any),])*100,2))
(pct800a_pop2 <- round (nrow (base[!is.na (base$n800_d45_wrelAbsPop_any) & base$n800_d45_wequal_any==0,]) / nrow (base[!is.na (base$n800_d45_wrelAbsPop_any),])*100,2))
(pct800b_pop <- round (nrow (base[!is.na (base$n800_d90_wrelAbsPop_any) & base$n800_d90_wrelAbsPop_any==0,]) / nrow (base[!is.na (base$n800_d90_wrelAbsPop_any),])*100,2))
(pct800b_pop2 <- round (nrow (base[!is.na (base$n800_d90_wrelAbsPop_any) & base$n800_d90_wequal_any==0,]) / nrow (base[!is.na (base$n800_d90_wrelAbsPop_any),])*100,2))
(pct800c_pop <- round (nrow (base[!is.na (base$n800_d120_wrelAbsPop_any) & base$n800_d120_wrelAbsPop_any==0,]) / nrow (base[!is.na (base$n800_d120_wrelAbsPop_any),])*100,2))
(pct800c_pop2 <- round (nrow (base[!is.na (base$n800_d120_wrelAbsPop_any) & base$n800_d120_wequal_any==0,]) / nrow (base[!is.na (base$n800_d120_wrelAbsPop_any),])*100,2))

(pct800a_repr <- round (nrow (base[!is.na (base$n800_d45_wrelAbsRepr_any) & base$n800_d45_wrelAbsRepr_any==0,]) / nrow (base[!is.na (base$n800_d45_wrelAbsRepr_any),])*100,2))
(pct800a_repr2 <- round (nrow (base[!is.na (base$n800_d45_wrelAbsRepr_any) & base$n800_d45_wequal_any==0,]) / nrow (base[!is.na (base$n800_d45_wrelAbsRepr_any),])*100,2))
(pct800b_repr <- round (nrow (base[!is.na (base$n800_d90_wrelAbsRepr_any) & base$n800_d90_wrelAbsRepr_any==0,]) / nrow (base[!is.na (base$n800_d90_wrelAbsRepr_any),])*100,2))
(pct800b_repr2 <- round (nrow (base[!is.na (base$n800_d90_wrelAbsRepr_any) & base$n800_d90_wequal_any==0,]) / nrow (base[!is.na (base$n800_d90_wrelAbsRepr_any),])*100,2))
(pct800c_repr <- round (nrow (base[!is.na (base$n800_d120_wrelAbsRepr_any) & base$n800_d120_wrelAbsRepr_any==0,]) / nrow (base[!is.na (base$n800_d120_wrelAbsRepr_any),])*100,2))
(pct800c_repr2 <- round (nrow (base[!is.na (base$n800_d120_wrelAbsRepr_any) & base$n800_d120_wequal_any==0,]) / nrow (base[!is.na (base$n800_d120_wrelAbsRepr_any),])*100,2))

(pct800a_piv <- round (nrow (base[!is.na (base$n800_d45_wrelAbsPolity_any) & base$n800_d45_wrelAbsPolity_any==0,]) / nrow (base[!is.na (base$n800_d45_wrelAbsPolity_any),])*100,2))
(pct800a_piv2 <- round (nrow (base[!is.na (base$n800_d45_wrelAbsPolity_any) & base$n800_d45_wequal_any==0,]) / nrow (base[!is.na (base$n800_d45_wrelAbsPolity_any),])*100,2))
(pct800b_piv <- round (nrow (base[!is.na (base$n800_d90_wrelAbsPolity_any) & base$n800_d90_wrelAbsPolity_any==0,]) / nrow (base[!is.na (base$n800_d90_wrelAbsPolity_any),])*100,2))
(pct800b_piv2 <- round (nrow (base[!is.na (base$n800_d90_wrelAbsPolity_any) & base$n800_d90_wequal_any==0,]) / nrow (base[!is.na (base$n800_d90_wrelAbsPolity_any),])*100,2))
(pct800c_piv <- round (nrow (base[!is.na (base$n800_d120_wrelAbsPolity_any) & base$n800_d120_wrelAbsPolity_any==0,]) / nrow (base[!is.na (base$n800_d120_wrelAbsPolity_any),])*100,2))
(pct800c_piv2 <- round (nrow (base[!is.na (base$n800_d120_wrelAbsPolity_any) & base$n800_d120_wequal_any==0,]) / nrow (base[!is.na (base$n800_d120_wrelAbsPolity_any),])*100,2))



### (2.2) Statistical analysis

## (2.2.1) Preparing the data still further

## creating some additional variables
base$year <- as.numeric (format (base$date, "%Y"))
base$pbega2 <- base$pbega*100

## taking logs
e <- 0.0001 ## we'll add this to the 0's
base$wdi_GDPcap_lag <- log (base$wdi_GDPcap_lag)
base$gdp_lag <- log (base$gdp_lag)
base$pop_lag <- log (base$pop_lag)

# contiguous neighbors
base$n50_d45_wabsGDP_any <- log (base$n50_d45_wabsGDP_any+e)
base$n50_d90_wabsGDP_any <- log (base$n50_d90_wabsGDP_any+e)
base$n50_d120_wabsGDP_any <- log (base$n50_d120_wabsGDP_any+e)
base$n50_d45_wrelGDP_any <- log (base$n50_d45_wrelGDP_any+e)
base$n50_d90_wrelGDP_any <- log (base$n50_d90_wrelGDP_any+e)
base$n50_d120_wrelGDP_any <- log (base$n50_d120_wrelGDP_any+e)
base$n50_d45_wabsPop_any <- log (base$n50_d45_wabsPop_any+e)
base$n50_d90_wabsPop_any <- log (base$n50_d90_wabsPop_any+e)
base$n50_d120_wabsPop_any <- log (base$n50_d120_wabsPop_any+e)
base$n50_d45_wrelPop_any <- log (base$n50_d45_wrelPop_any+e)
base$n50_d90_wrelPop_any <- log (base$n50_d90_wrelPop_any+e)
base$n50_d120_wrelPop_any <- log (base$n50_d120_wrelPop_any+e)
base$n50_d45_wabsMil_any <- log (base$n50_d45_wabsMil_any+e)
base$n50_d90_wabsMil_any <- log (base$n50_d90_wabsMil_any+e)
base$n50_d120_wabsMil_any <- log (base$n50_d120_wabsMil_any+e)
base$n50_d45_wrelMil_any <- log (base$n50_d45_wrelMil_any+e)
base$n50_d90_wrelMil_any <- log (base$n50_d90_wrelMil_any+e)
base$n50_d120_wrelMil_any <- log (base$n50_d120_wrelMil_any+e)
base$n50_d45_wabsPers_any <- log (base$n50_d45_wabsPers_any+e)
base$n50_d90_wabsPers_any <- log (base$n50_d90_wabsPers_any+e)
base$n50_d120_wabsPers_any <- log (base$n50_d120_wabsPers_any+e)
base$n50_d45_wrelPers_any <- log (base$n50_d45_wrelPers_any+e)
base$n50_d90_wrelPers_any <- log (base$n50_d90_wrelPers_any+e)
base$n50_d120_wrelPers_any <- log (base$n50_d120_wrelPers_any+e)

# 800km neighbors
base$n800_d45_wabsGDP_any <- log (base$n800_d45_wabsGDP_any+e)
base$n800_d90_wabsGDP_any <- log (base$n800_d90_wabsGDP_any+e)
base$n800_d120_wabsGDP_any <- log (base$n800_d120_wabsGDP_any+e)
base$n800_d45_wrelGDP_any <- log (base$n800_d45_wrelGDP_any+e)
base$n800_d90_wrelGDP_any <- log (base$n800_d90_wrelGDP_any+e)
base$n800_d120_wrelGDP_any <- log (base$n800_d120_wrelGDP_any+e)
base$n800_d45_wabsPop_any <- log (base$n800_d45_wabsPop_any+e)
base$n800_d90_wabsPop_any <- log (base$n800_d90_wabsPop_any+e)
base$n800_d120_wabsPop_any <- log (base$n800_d120_wabsPop_any+e)
base$n800_d45_wrelPop_any <- log (base$n800_d45_wrelPop_any+e)
base$n800_d90_wrelPop_any <- log (base$n800_d90_wrelPop_any+e)
base$n800_d120_wrelPop_any <- log (base$n800_d120_wrelPop_any+e)
base$n800_d45_wabsMil_any <- log (base$n800_d45_wabsMil_any+e)
base$n800_d90_wabsMil_any <- log (base$n800_d90_wabsMil_any+e)
base$n800_d120_wabsMil_any <- log (base$n800_d120_wabsMil_any+e)
base$n800_d45_wrelMil_any <- log (base$n800_d45_wrelMil_any+e)
base$n800_d90_wrelMil_any <- log (base$n800_d90_wrelMil_any+e)
base$n800_d120_wrelMil_any <- log (base$n800_d120_wrelMil_any+e)
base$n800_d45_wabsPers_any <- log (base$n800_d45_wabsPers_any+e)
base$n800_d90_wabsPers_any <- log (base$n800_d90_wabsPers_any+e)
base$n800_d120_wabsPers_any <- log (base$n800_d120_wabsPers_any+e)
base$n800_d45_wrelPers_any <- log (base$n800_d45_wrelPers_any+e)
base$n800_d90_wrelPers_any <- log (base$n800_d90_wrelPers_any+e)
base$n800_d120_wrelPers_any <- log (base$n800_d120_wrelPers_any+e)

# same UN region
base$nUN_d45_wabsGDP_any <- log (base$nUN_d45_wabsGDP_any+e)
base$nUN_d90_wabsGDP_any <- log (base$nUN_d90_wabsGDP_any+e)
base$nUN_d120_wabsGDP_any <- log (base$nUN_d120_wabsGDP_any+e)
base$nUN_d45_wrelGDP_any <- log (base$nUN_d45_wrelGDP_any+e)
base$nUN_d90_wrelGDP_any <- log (base$nUN_d90_wrelGDP_any+e)
base$nUN_d120_wrelGDP_any <- log (base$nUN_d120_wrelGDP_any+e)
base$nUN_d45_wabsPop_any <- log (base$nUN_d45_wabsPop_any+e)
base$nUN_d90_wabsPop_any <- log (base$nUN_d90_wabsPop_any+e)
base$nUN_d120_wabsPop_any <- log (base$nUN_d120_wabsPop_any+e)
base$nUN_d45_wrelPop_any <- log (base$nUN_d45_wrelPop_any+e)
base$nUN_d90_wrelPop_any <- log (base$nUN_d90_wrelPop_any+e)
base$nUN_d120_wrelPop_any <- log (base$nUN_d120_wrelPop_any+e)
base$nUN_d45_wabsMil_any <- log (base$nUN_d45_wabsMil_any+e)
base$nUN_d90_wabsMil_any <- log (base$nUN_d90_wabsMil_any+e)
base$nUN_d120_wabsMil_any <- log (base$nUN_d120_wabsMil_any+e)
base$nUN_d45_wrelMil_any <- log (base$nUN_d45_wrelMil_any+e)
base$nUN_d90_wrelMil_any <- log (base$nUN_d90_wrelMil_any+e)
base$nUN_d120_wrelMil_any <- log (base$nUN_d120_wrelMil_any+e)
base$nUN_d45_wabsPers_any <- log (base$nUN_d45_wabsPers_any+e)
base$nUN_d90_wabsPers_any <- log (base$nUN_d90_wabsPers_any+e)
base$nUN_d120_wabsPers_any <- log (base$nUN_d120_wabsPers_any+e)
base$nUN_d45_wrelPers_any <- log (base$nUN_d45_wrelPers_any+e)
base$nUN_d90_wrelPers_any <- log (base$nUN_d90_wrelPers_any+e)
base$nUN_d120_wrelPers_any <- log (base$nUN_d120_wrelPers_any+e)


## (2.2.2) Main results: Models in Table 3, cols. 1-6

# listing the explanatory variables
vCont01 <- c ("n50_d30_wequal_any", "n50_d45_wequal_any", "n50_d90_wequal_any", "n50_d120_wequal_any", "n50_d360_wequal_any"
              , "n50_d30_wequal_sum", "n50_d45_wequal_sum", "n50_d90_wequal_sum", "n50_d120_wequal_sum", "n50_d360_wequal_sum")
vN80001 <- c ("n800_d30_wequal_any", "n800_d45_wequal_any", "n800_d90_wequal_any", "n800_d120_wequal_any", "n800_d360_wequal_any"
              , "n800_d30_wequal_sum", "n800_d45_wequal_sum", "n800_d90_wequal_sum", "n800_d120_wequal_sum", "n800_d360_wequal_sum")
vUNReg01 <- c ("nUN_d30_wequal_any", "nUN_d45_wequal_any", "nUN_d90_wequal_any", "nUN_d120_wequal_any", "nUN_d360_wequal_any"
               , "nUN_d30_wequal_sum", "nUN_d45_wequal_sum", "nUN_d90_wequal_sum", "nUN_d120_wequal_sum", "nUN_d360_wequal_sum")

# running one model to get the number of observations
(sumNobsCont01a <- summary (NobsCont01a <- felm (pbega2 ~ n50_d45_wequal_any | 0 | 0 | 0, data=base)))
(sumNobsCont01b <- summary (NobsCont01b <- felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | 0, data=base)))
(sumNobsCont01c <- summary (NobsCont01c <- felm (pbega2 ~ n50_d45_wequal_any | 0 | 0 | country, data=base)))
(sumNobsCont01d <- summary (NobsCont01d <- felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base)))
(sumNobsCont01e <- summary (NobsCont01e <- felm (pbega2 ~ n50_d45_wequal_any + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=base)))

(sumNobsN80001a <- summary (NobsN80001a <- felm (pbega2 ~ n800_d45_wequal_any | 0 | 0 | 0, data=base)))
(sumNobsN80001b <- summary (NobsN80001b <- felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | 0, data=base)))
(sumNobsN80001c <- summary (NobsN80001c <- felm (pbega2 ~ n800_d45_wequal_any | 0 | 0 | country, data=base)))
(sumNobsN80001d <- summary (NobsN80001d <- felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base)))
(sumNobsN80001e <- summary (NobsN80001e <- felm (pbega2 ~ n800_d45_wequal_any + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=base)))

(sumNobsUNReg01a <- summary (NobsUNReg01a <- felm (pbega2 ~ nUN_d45_wequal_any | 0 | 0 | 0, data=base)))
(sumNobsUNReg01b <- summary (NobsUNReg01b <- felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | 0, data=base)))
(sumNobsUNReg01c <- summary (NobsUNReg01c <- felm (pbega2 ~ nUN_d45_wequal_any | 0 | 0 | country, data=base)))
(sumNobsUNReg01d <- summary (NobsUNReg01d <- felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base)))
(sumNobsUNReg01e <- summary (NobsUNReg01e <- felm (pbega2 ~ nUN_d45_wequal_any + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=base)))

# getting the number of observations
(nobsCont01main <- c (length (unique (base[!is.na (base$n50_d45_wequal_any),]$country))
                      , length (unique (NobsCont01d$fe$countryYear))
                      , NobsCont01d$N))
(nobsN80001main <- c (length (unique (base[!is.na (base$n800_d45_wequal_any),]$country))
                      , length (unique (NobsN80001d$fe$countryYear))
                      , NobsN80001d$N))
(nobsUNReg01main <- c (length (unique (base[!is.na (base$nUN_d45_wequal_any),]$country))
                       , length (unique (NobsUNReg01d$fe$countryYear))
                       , NobsUNReg01d$N))

(nobsCont01controls <- c (length (unique (base[!is.na (base$n50_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$country))
                          , length (unique (base[!is.na (base$n50_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$countryYear))
                          , NobsCont01e$N))
(nobsN80001controls <- c (length (unique (base[!is.na (base$n800_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$country))
                          , length (unique (base[!is.na (base$n800_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$countryYear))
                          , NobsN80001e$N))
(nobsUNReg01controls <- c (length (unique (base[!is.na (base$nUN_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$country))
                           , length (unique (base[!is.na (base$nUN_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$countryYear))
                           , NobsUNReg01e$N))

(nobsCont01decade <- c (length (unique (base[!is.na (base$n50_d45_wequal_any),]$country))
                        , length (unique (base[!is.na (base$n50_d45_wequal_any),]$cdecade))
                        , NobsCont01d$N))
(nobsN80001decade <- c (length (unique (base[!is.na (base$n800_d45_wequal_any),]$country))
                        , length (unique (base[!is.na (base$n800_d45_wequal_any),]$cdecade))
                        , NobsN80001d$N))
(nobsUNReg01decade <- c (length (unique (base[!is.na (base$nUN_d45_wequal_any),]$country))
                         , length (unique (base[!is.na (base$nUN_d45_wequal_any),]$cdecade))
                         , NobsUNReg01d$N))

(nobsCont01decade2 <- c (length (unique (base[!is.na (base$n50_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$country))
                         , length (unique (base[!is.na (base$n50_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$cdecade))
                         , NobsCont01e$N))
(nobsN80001decade2 <- c (length (unique (base[!is.na (base$n800_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$country))
                         , length (unique (base[!is.na (base$n800_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$cdecade))
                         , NobsN80001e$N))
(nobsUNReg01decade2 <- c (length (unique (base[!is.na (base$nUN_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$country))
                          , length (unique (base[!is.na (base$nUN_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$cdecade))
                          , NobsUNReg01e$N))

(nobsCont01ryear <- c (length (unique (base[!is.na (base$n50_d45_wequal_any),]$country))
                       , length (unique (base[!is.na (base$n50_d45_wequal_any),]$ryear))
                       , NobsCont01d$N))
(nobsN80001ryear <- c (length (unique (base[!is.na (base$n800_d45_wequal_any),]$country))
                       , length (unique (base[!is.na (base$n800_d45_wequal_any),]$ryear))
                       , NobsN80001d$N))
(nobsUNReg01ryear <- c (length (unique (base[!is.na (base$nUN_d45_wequal_any),]$country))
                        , length (unique (base[!is.na (base$nUN_d45_wequal_any),]$ryear))
                        , NobsUNReg01d$N))

(nobsCont01ryear2 <- c (length (unique (base[!is.na (base$n50_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$country))
                        , length (unique (base[!is.na (base$n50_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$ryear))
                        , NobsCont01e$N))
(nobsN80001ryear2 <- c (length (unique (base[!is.na (base$n800_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$country))
                        , length (unique (base[!is.na (base$n800_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$ryear))
                        , NobsN80001e$N))
(nobsUNReg01ryear2 <- c (length (unique (base[!is.na (base$nUN_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$country))
                         , length (unique (base[!is.na (base$nUN_d45_wequal_any) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcap_lag) & !is.na (base$wdi_GDPcapGrowth_lag) & !is.na (base$pop_lag) & !is.na (base$physint_lag) & !is.na (base$polity),]$ryear))
                         , NobsUNReg01e$N))

# doing the loop
v <- NULL
mCont01 <- mN80001 <- mUNReg01 <- list () ## we'll put the models here
mCont01.vcov <- mN80001.vcov <- mUNReg01.vcov <- list () ## we'll put the variance-covariance matrices (for models with election interactions) here

system.time (
  for (v in 1:length (vCont01)){
    
    ## defining the explanatory variable of interest
    base$ivCont <- base[,vCont01[v]]
    base$ivN800 <- base[,vN80001[v]]
    base$ivUNReg <- base[,vUNReg01[v]]
    
    ## (i) Contiguous neighbors
    
    # country-year FEs
    mCont01[[v+0*length (vCont01)]] <- summary (felm (pbega2 ~ ivCont | countryYear | 0 | country, data=base))$coef
    mCont01[[v+1*length (vCont01)]] <- summary (felm (pbega2 ~ ivCont + ele30 | countryYear | 0 | country, data=base))$coef
    mCont01[[v+2*length (vCont01)]] <- summary (felm (pbega2 ~ ivCont + I(ivCont*ele30) + ele30 | countryYear | 0 | country, data=base))$coef
    mCont01[[v+3*length (vCont01)]] <- summary (felm (pbega2 ~ ivCont + I(ivCont*physint_lag) + physint_lag | countryYear | 0 | country, data=base))$coef
    
    # variance/covariance matrices for models with interactions w/election
    mCont01.vcov[[v+0*length (vCont01)]] <- vcov (felm (pbega2 ~ ivCont + I(ivCont*ele30) + ele30 | countryYear | 0 | country, data=base))
    
    
    ## (ii) 800km neighbors
    
    # country-year FEs
    mN80001[[v+0*length (vN80001)]] <- summary (felm (pbega2 ~ ivN800 | countryYear | 0 | country, data=base))$coef
    mN80001[[v+1*length (vN80001)]] <- summary (felm (pbega2 ~ ivN800 + ele30 | countryYear | 0 | country, data=base))$coef
    mN80001[[v+2*length (vN80001)]] <- summary (felm (pbega2 ~ ivN800 + I(ivN800*ele30) + ele30 | countryYear | 0 | country, data=base))$coef
    mN80001[[v+3*length (vN80001)]] <- summary (felm (pbega2 ~ ivN800 + I(ivN800*physint_lag) + physint_lag | countryYear | 0 | country, data=base))$coef
    
    # variance/covariance matrices for models with interactions w/election
    mN80001.vcov[[v+0*length (vN80001)]] <- vcov (felm (pbega2 ~ ivN800 + I(ivN800*ele30) + ele30 | countryYear | 0 | country, data=base))
    
    
    ## (iii) UN region neighbors
    
    # country-year FEs
    mUNReg01[[v+0*length (vUNReg01)]] <- summary (felm (pbega2 ~ ivUNReg | countryYear | 0 | country, data=base))$coef
    mUNReg01[[v+1*length (vUNReg01)]] <- summary (felm (pbega2 ~ ivUNReg + ele30 | countryYear | 0 | country, data=base))$coef
    mUNReg01[[v+2*length (vUNReg01)]] <- summary (felm (pbega2 ~ ivUNReg + I(ivUNReg*ele30) + ele30 | countryYear | 0 | country, data=base))$coef
    mUNReg01[[v+3*length (vUNReg01)]] <- summary (felm (pbega2 ~ ivUNReg + I(ivUNReg*physint_lag) + physint_lag | countryYear | 0 | country, data=base))$coef
    
    # variance/covariance matrices for models with interactions w/election
    mUNReg01.vcov[[v+0*length (vUNReg01)]] <- vcov (felm (pbega2 ~ ivUNReg + I(ivUNReg*ele30) + ele30 | countryYear | 0 | country, data=base))
  }
)   ## 947 seconds


## (2.2.3) Additional results (I): Weighting protests by NEIGHBOR characteristics

# listing the explanatory variables
vCont02 <- c ("n50_d45_wabsGDP_any", "n50_d90_wabsGDP_any", "n50_d120_wabsGDP_any"
              , "n50_d45_wrelGDP_any", "n50_d90_wrelGDP_any", "n50_d120_wrelGDP_any"
              , "n50_d45_wrelAbsGDPcap_any", "n50_d90_wrelAbsGDPcap_any", "n50_d120_wrelAbsGDPcap_any"
              , "n50_d45_wabsPop_any", "n50_d90_wabsPop_any", "n50_d120_wabsPop_any"
              , "n50_d45_wrelPop_any", "n50_d90_wrelPop_any", "n50_d120_wrelPop_any"
              , "n50_d45_wrelAbsPop_any", "n50_d90_wrelAbsPop_any", "n50_d120_wrelAbsPop_any"
              , "n50_d45_wabsMil_any", "n50_d90_wabsMil_any", "n50_d120_wabsMil_any"
              , "n50_d45_wrelMil_any", "n50_d90_wrelMil_any", "n50_d120_wrelMil_any"
              , "n50_d45_wabsPers_any", "n50_d90_wabsPers_any", "n50_d120_wabsPers_any"
              , "n50_d45_wrelPers_any", "n50_d90_wrelPers_any", "n50_d120_wrelPers_any"
              , "n50_d45_wrelAbsRepr_any", "n50_d90_wrelAbsRepr_any", "n50_d120_wrelAbsRepr_any"
              , "n50_d45_wrelAbsPolity_any", "n50_d90_wrelAbsPolity_any", "n50_d120_wrelAbsPolity_any"
              , "n50_d45_wrelAbsPolyarchy_any", "n50_d90_wrelAbsPolyarchy_any", "n50_d120_wrelAbsPolyarchy_any")
vN80002 <- c ("n800_d45_wabsGDP_any", "n800_d90_wabsGDP_any", "n800_d120_wabsGDP_any"
              , "n800_d45_wrelGDP_any", "n800_d90_wrelGDP_any", "n800_d120_wrelGDP_any"
              , "n800_d45_wrelAbsGDPcap_any", "n800_d90_wrelAbsGDPcap_any", "n800_d120_wrelAbsGDPcap_any"
              , "n800_d45_wabsPop_any", "n800_d90_wabsPop_any", "n800_d120_wabsPop_any"
              , "n800_d45_wrelPop_any", "n800_d90_wrelPop_any", "n800_d120_wrelPop_any"
              , "n800_d45_wrelAbsPop_any", "n800_d90_wrelAbsPop_any", "n800_d120_wrelAbsPop_any"
              , "n800_d45_wabsMil_any", "n800_d90_wabsMil_any", "n800_d120_wabsMil_any"
              , "n800_d45_wrelMil_any", "n800_d90_wrelMil_any", "n800_d120_wrelMil_any"
              , "n800_d45_wabsPers_any", "n800_d90_wabsPers_any", "n800_d120_wabsPers_any"
              , "n800_d45_wrelPers_any", "n800_d90_wrelPers_any", "n800_d120_wrelPers_any"
              , "n800_d45_wrelAbsRepr_any", "n800_d90_wrelAbsRepr_any", "n800_d120_wrelAbsRepr_any"
              , "n800_d45_wrelAbsPolity_any", "n800_d90_wrelAbsPolity_any", "n800_d120_wrelAbsPolity_any"
              , "n800_d45_wrelAbsPolyarchy_any", "n800_d90_wrelAbsPolyarchy_any", "n800_d120_wrelAbsPolyarchy_any")
vUNReg02 <- c ("nUN_d45_wabsGDP_any", "nUN_d90_wabsGDP_any", "nUN_d120_wabsGDP_any"
               , "nUN_d45_wrelGDP_any", "nUN_d90_wrelGDP_any", "nUN_d120_wrelGDP_any"
               , "nUN_d45_wrelAbsGDPcap_any", "nUN_d90_wrelAbsGDPcap_any", "nUN_d120_wrelAbsGDPcap_any"
               , "nUN_d45_wabsPop_any", "nUN_d90_wabsPop_any", "nUN_d120_wabsPop_any"
               , "nUN_d45_wrelPop_any", "nUN_d90_wrelPop_any", "nUN_d120_wrelPop_any"
               , "nUN_d45_wrelAbsPop_any", "nUN_d90_wrelAbsPop_any", "nUN_d120_wrelAbsPop_any"
               , "nUN_d45_wabsMil_any", "nUN_d90_wabsMil_any", "nUN_d120_wabsMil_any"
               , "nUN_d45_wrelMil_any", "nUN_d90_wrelMil_any", "nUN_d120_wrelMil_any"
               , "nUN_d45_wabsPers_any", "nUN_d90_wabsPers_any", "nUN_d120_wabsPers_any"
               , "nUN_d45_wrelPers_any", "nUN_d90_wrelPers_any", "nUN_d120_wrelPers_any"
               , "nUN_d45_wrelAbsRepr_any", "nUN_d90_wrelAbsRepr_any", "nUN_d120_wrelAbsRepr_any"
               , "nUN_d45_wrelAbsPolity_any", "nUN_d90_wrelAbsPolity_any", "nUN_d120_wrelAbsPolity_any"
               , "nUN_d45_wrelAbsPolyarchy_any", "nUN_d90_wrelAbsPolyarchy_any", "nUN_d120_wrelAbsPolyarchy_any")

# running one model to get the number of observations
(sumNobsCont02a.high <- summary (NobsCont02a.high <- felm (pbega2 ~ n50_d45_wabsGDP_any | 0 | 0 | 0, data=base)))
(sumNobsCont02b.high <- summary (NobsCont02b.high <- felm (pbega2 ~ n50_d45_wabsGDP_any | countryYear | 0 | 0, data=base)))
(sumNobsCont02c.high <- summary (NobsCont02c.high <- felm (pbega2 ~ n50_d45_wabsGDP_any | 0 | 0 | country, data=base)))
(sumNobsCont02d.high <- summary (NobsCont02d.high <- felm (pbega2 ~ n50_d45_wabsGDP_any | countryYear | 0 | country, data=base)))
(sumNobsCont02a.low <- summary (NobsCont02a.low <- felm (pbega2 ~ n50_d45_wrelMil_any | 0 | 0 | 0, data=base)))
(sumNobsCont02b.low <- summary (NobsCont02b.low <- felm (pbega2 ~ n50_d45_wrelMil_any | countryYear | 0 | 0, data=base)))
(sumNobsCont02c.low <- summary (NobsCont02c.low <- felm (pbega2 ~ n50_d45_wrelMil_any | 0 | 0 | country, data=base)))
(sumNobsCont02d.low <- summary (NobsCont02d.low <- felm (pbega2 ~ n50_d45_wrelMil_any | countryYear | 0 | country, data=base)))

(sumNobsN80002a.high <- summary (NobsN80002a.high <- felm (pbega2 ~ n800_d45_wabsGDP_any | 0 | 0 | 0, data=base)))
(sumNobsN80002b.high <- summary (NobsN80002b.high <- felm (pbega2 ~ n800_d45_wabsGDP_any | countryYear | 0 | 0, data=base)))
(sumNobsN80002c.high <- summary (NobsN80002c.high <- felm (pbega2 ~ n800_d45_wabsGDP_any | 0 | 0 | country, data=base)))
(sumNobsN80002d.high <- summary (NobsN80002d.high <- felm (pbega2 ~ n800_d45_wabsGDP_any | countryYear | 0 | country, data=base)))
(sumNobsN80002a.low <- summary (NobsN80002a.low <- felm (pbega2 ~ n800_d45_wrelMil_any | 0 | 0 | 0, data=base)))
(sumNobsN80002b.low <- summary (NobsN80002b.low <- felm (pbega2 ~ n800_d45_wrelMil_any | countryYear | 0 | 0, data=base)))
(sumNobsN80002c.low <- summary (NobsN80002c.low <- felm (pbega2 ~ n800_d45_wrelMil_any | 0 | 0 | country, data=base)))
(sumNobsN80002d.low <- summary (NobsN80002d.low <- felm (pbega2 ~ n800_d45_wrelMil_any | countryYear | 0 | country, data=base)))

(sumNobsUNReg02a.high <- summary (NobsUNReg02a.high <- felm (pbega2 ~ nUN_d45_wabsGDP_any | 0 | 0 | 0, data=base)))
(sumNobsUNReg02b.high <- summary (NobsUNReg02b.high <- felm (pbega2 ~ nUN_d45_wabsGDP_any | countryYear | 0 | 0, data=base)))
(sumNobsUNReg02c.high <- summary (NobsUNReg02c.high <- felm (pbega2 ~ nUN_d45_wabsGDP_any | 0 | 0 | country, data=base)))
(sumNobsUNReg02d.high <- summary (NobsUNReg02d.high <- felm (pbega2 ~ nUN_d45_wabsGDP_any | countryYear | 0 | country, data=base)))
(sumNobsUNReg02a.low <- summary (NobsUNReg02a.low <- felm (pbega2 ~ nUN_d45_wrelMil_any | 0 | 0 | 0, data=base)))
(sumNobsUNReg02b.low <- summary (NobsUNReg02b.low <- felm (pbega2 ~ nUN_d45_wrelMil_any | countryYear | 0 | 0, data=base)))
(sumNobsUNReg02c.low <- summary (NobsUNReg02c.low <- felm (pbega2 ~ nUN_d45_wrelMil_any | 0 | 0 | country, data=base)))
(sumNobsUNReg02d.low <- summary (NobsUNReg02d.low <- felm (pbega2 ~ nUN_d45_wrelMil_any | countryYear | 0 | country, data=base)))

# getting the number of observations
(nobsCont02.low <- c (length (unique (base[!is.na (base$n50_d45_wrelMil_any),]$country))
                      , length (unique (NobsCont02d.low$fe$countryYear))
                      , NobsCont02d.low$N))
(nobsN80002.low <- c (length (unique (base[!is.na (base$n800_d45_wrelMil_any),]$country))
                      , length (unique (NobsN80002d.low$fe$countryYear))
                      , NobsN80002d.low$N))
(nobsUNReg02.low <- c (length (unique (base[!is.na (base$nUN_d45_wrelMil_any),]$country))
                       , length (unique (NobsUNReg02d.low$fe$countryYear))
                       , NobsUNReg02d.low$N))
(nobsCont02.high <- c (length (unique (base[!is.na (base$n50_d45_wabsGDP_any),]$country))
                       , length (unique (NobsCont02d.high$fe$countryYear))
                       , NobsCont02d.high$N))
(nobsN80002.high <- c (length (unique (base[!is.na (base$n800_d45_wabsGDP_any),]$country))
                       , length (unique (NobsN80002d.high$fe$countryYear))
                       , NobsN80002d.high$N))
(nobsUNReg02.high <- c (length (unique (base[!is.na (base$nUN_d45_wabsGDP_any),]$country))
                        , length (unique (NobsUNReg02d.high$fe$countryYear))
                        , NobsUNReg02d.high$N))

# doing the loop
v <- NULL
mCont02 <- mN80002 <- mUNReg02 <- list ()

system.time (
  for (v in 1:length (vCont02)){
    
    ## defining the explanatory variable of interest
    base$ivCont <- base[,vCont02[v]]
    base$ivN800 <- base[,vN80002[v]]
    base$ivUNReg <- base[,vUNReg02[v]]
    
    ## (i) Contiguous neighbors
    
    # country-year FEs
    mCont02[[v+0*length (vCont02)]] <- summary (felm (pbega2 ~ ivCont | countryYear | 0 | country, data=base))$coef
    mCont02[[v+1*length (vCont02)]] <- summary (felm (pbega2 ~ ivCont + ele30 | countryYear | 0 | country, data=base))$coef
    mCont02[[v+2*length (vCont02)]] <- summary (felm (pbega2 ~ ivCont + I(ivCont*ele30) + ele30 | countryYear | 0 | country, data=base))$coef
    
    ## (ii) 800km neighbors
    
    # country-year FEs
    mN80002[[v+0*length (vN80002)]] <- summary (felm (pbega2 ~ ivN800 | countryYear | 0 | country, data=base))$coef
    mN80002[[v+1*length (vN80002)]] <- summary (felm (pbega2 ~ ivN800 + ele30 | countryYear | 0 | country, data=base))$coef
    mN80002[[v+2*length (vN80002)]] <- summary (felm (pbega2 ~ ivN800 + I(ivN800*ele30) + ele30 | countryYear | 0 | country, data=base))$coef
    
    ## (iii) UN region neighbors
    
    # country-year FEs
    mUNReg02[[v+0*length (vUNReg02)]] <- summary (felm (pbega2 ~ ivUNReg | countryYear | 0 | country, data=base))$coef
    mUNReg02[[v+1*length (vUNReg02)]] <- summary (felm (pbega2 ~ ivUNReg + ele30 | countryYear | 0 | country, data=base))$coef
    mUNReg02[[v+2*length (vUNReg02)]] <- summary (felm (pbega2 ~ ivUNReg + I(ivUNReg*ele30) + ele30 | countryYear | 0 | country, data=base))$coef
  }
) ## 1433 seconds


## (2.2.4) Additional results (II): Weighting protests according to PROTEST characteristics

# listing the explanatory variables
vCont03 <- c (
  "n50_d45_wSize_any", "n50_d90_wSize_any", "n50_d120_wSize_any"
  , "n50_d45_wSuc_any2", "n50_d90_wSuc_any2", "n50_d120_wSuc_any2"
  , "n50_d45_wSuc2_any2", "n50_d90_wSuc2_any2", "n50_d120_wSuc2_any2"
  , "n50_d45_wRepr_any2", "n50_d90_wRepr_any2", "n50_d120_wRepr_any2"
  , "n50_d45_wElec_any", "n50_d90_wElec_any", "n50_d120_wElec_any"
  , "n50_d45_wViol_any2", "n50_d90_wViol_any2", "n50_d120_wViol_any2")
vN80003 <- c (
  "n800_d45_wSize_any", "n800_d90_wSize_any", "n800_d120_wSize_any"
  , "n800_d45_wSuc_any2", "n800_d90_wSuc_any2", "n800_d120_wSuc_any2"
  , "n800_d45_wSuc2_any2", "n800_d90_wSuc2_any2", "n800_d120_wSuc2_any2"
  , "n800_d45_wRepr_any2", "n800_d90_wRepr_any2", "n800_d120_wRepr_any2"
  , "n800_d45_wElec_any", "n800_d90_wElec_any", "n800_d120_wElec_any"
  , "n800_d45_wViol_any2", "n800_d90_wViol_any2", "n800_d120_wViol_any2")
vUNReg03 <- c (
  "nUN_d45_wSize_any", "nUN_d90_wSize_any", "nUN_d120_wSize_any"
  , "nUN_d45_wSuc_any2", "nUN_d90_wSuc_any2", "nUN_d120_wSuc_any2"
  , "nUN_d45_wSuc2_any2", "nUN_d90_wSuc2_any2", "nUN_d120_wSuc2_any2"
  , "nUN_d45_wRepr_any2", "nUN_d90_wRepr_any2", "nUN_d120_wRepr_any2"
  , "nUN_d45_wElec_any", "nUN_d90_wElec_any", "nUN_d120_wElec_any"
  , "nUN_d45_wViol_any2", "nUN_d90_wViol_any2", "nUN_d120_wViol_any2")

# running one model to get the number of observations
(sumNobsCont03a <- summary (NobsCont03a <- felm (pbega2 ~ n50_d45_wSize_any | 0 | 0 | 0, data=base)))
(sumNobsCont03b <- summary (NobsCont03b <- felm (pbega2 ~ n50_d45_wSize_any | countryYear | 0 | 0, data=base)))
(sumNobsCont03c <- summary (NobsCont03c <- felm (pbega2 ~ n50_d45_wSize_any | 0 | 0 | country, data=base)))
(sumNobsCont03d <- summary (NobsCont03d <- felm (pbega2 ~ n50_d45_wSize_any | countryYear | 0 | country, data=base)))

(sumNobsN80003a <- summary (NobsN80003a <- felm (pbega2 ~ n800_d45_wSize_any | 0 | 0 | 0, data=base)))
(sumNobsN80003b <- summary (NobsN80003b <- felm (pbega2 ~ n800_d45_wSize_any | countryYear | 0 | 0, data=base)))
(sumNobsN80003c <- summary (NobsN80003c <- felm (pbega2 ~ n800_d45_wSize_any | 0 | 0 | country, data=base)))
(sumNobsN80003d <- summary (NobsN80003d <- felm (pbega2 ~ n800_d45_wSize_any | countryYear | 0 | country, data=base)))

(sumNobsUNReg03a <- summary (NobsUNReg03a <- felm (pbega2 ~ nUN_d45_wSize_any | 0 | 0 | 0, data=base)))
(sumNobsUNReg03b <- summary (NobsUNReg03b <- felm (pbega2 ~ nUN_d45_wSize_any | countryYear | 0 | 0, data=base)))
(sumNobsUNReg03c <- summary (NobsUNReg03c <- felm (pbega2 ~ nUN_d45_wSize_any | 0 | 0 | country, data=base)))
(sumNobsUNReg03d <- summary (NobsUNReg03d <- felm (pbega2 ~ nUN_d45_wSize_any | countryYear | 0 | country, data=base)))

# getting the number of observations
(nobsCont03 <- c (length (unique (base[!is.na (base$n50_d45_wSize_any),]$country))
                  , length (unique (NobsCont03d$fe$countryYear))
                  , NobsCont03d$N))
(nobsN80003 <- c (length (unique (base[!is.na (base$n800_d45_wSize_any),]$country))
                  , length (unique (NobsN80003d$fe$countryYear))
                  , NobsN80003d$N))
(nobsUNReg03 <- c (length (unique (base[!is.na (base$nUN_d45_wSize_any),]$country))
                   , length (unique (NobsUNReg03d$fe$countryYear))
                   , NobsUNReg03d$N))

# doing the loop
v <- NULL
mCont03 <- mN80003 <- mUNReg03 <- list ()

system.time (
  for (v in 1:length (vCont03)){
    
    ## defining the explanatory variable of interest
    base$ivCont <- base[,vCont03[v]]
    base$ivN800 <- base[,vN80003[v]]
    base$ivUNReg <- base[,vUNReg03[v]]
    
    ## (i) Contiguous neighbors
    
    # country-year FEs
    mCont03[[v+0*length (vCont03)]] <- summary (felm (pbega2 ~ ivCont | countryYear | 0 | country, data=base))$coef
    mCont03[[v+1*length (vCont03)]] <- summary (felm (pbega2 ~ ivCont + ele30 | countryYear | 0 | country, data=base))$coef
    mCont03[[v+2*length (vCont03)]] <- summary (felm (pbega2 ~ ivCont*ele30 | countryYear | 0 | country, data=base))$coef
    
    ## (ii) 800km neighbors
    
    # country-year FEs
    mN80003[[v+0*length (vN80003)]] <- summary (felm (pbega2 ~ ivN800 | countryYear | 0 | country, data=base))$coef
    mN80003[[v+1*length (vN80003)]] <- summary (felm (pbega2 ~ ivN800 + ele30 | countryYear | 0 | country, data=base))$coef
    mN80003[[v+2*length (vN80003)]] <- summary (felm (pbega2 ~ ivN800*ele30 | countryYear | 0 | country, data=base))$coef
    
    ## (iii) UN region neighbors
    
    # country-year FEs
    mUNReg03[[v+0*length (vUNReg03)]] <- summary (felm (pbega2 ~ ivUNReg | countryYear | 0 | country, data=base))$coef
    mUNReg03[[v+1*length (vUNReg03)]] <- summary (felm (pbega2 ~ ivUNReg + ele30 | countryYear | 0 | country, data=base))$coef
    mUNReg03[[v+2*length (vUNReg03)]] <- summary (felm (pbega2 ~ ivUNReg*ele30 | countryYear | 0 | country, data=base))$coef
  }
)  ## 626 seconds


## (2.2.5) Additional results (III): Sub-sample analyses

# (Internet era; Fall of communism (1989 and 1989-1992); Arab Spring; excluding borderline cases; democracies vs. autocracies)
mCont.int <- mN800.int <- mUNReg.int <- list () ## we'll put the models here
mCont.y89 <- mN800.y89 <- mUNReg.y89 <- list ()
mCont.pc <- mN800.pc <- mUNReg.pc <- list ()
mCont.aspring <- mN800.aspring <- mUNReg.aspring <- list ()
mCont.border <- mN800.border <- mUNReg.border <- list ()
mCont.aut <- mN800.aut <- mUNReg.aut <- list ()
mCont.autVD <- mN800.autVD <- mUNReg.autVD <- list ()
mCont.dem <- mN800.dem <- mUNReg.dem <- list ()
mCont.demVD <- mN800.demVD <- mUNReg.demVD <- list ()

system.time ({
  
  ## (i) Contiguous neighbors
  
  # (i.i) Internet era
  mCont.int[[1]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mCont.int[[2]] <- summary (felm (pbega2 ~ n50_d90_wequal_any | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mCont.int[[3]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mCont.int[[4]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mCont.int[[5]] <- summary (felm (pbega2 ~ n50_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mCont.int[[6]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  
  # (i.ii) fall of Communism
  mCont.pc[[1]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mCont.pc[[2]] <- summary (felm (pbega2 ~ n50_d90_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mCont.pc[[3]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mCont.pc[[4]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mCont.pc[[5]] <- summary (felm (pbega2 ~ n50_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mCont.pc[[6]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  
  # (i.iii) 1989 only
  mCont.y89[[1]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mCont.y89[[2]] <- summary (felm (pbega2 ~ n50_d90_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mCont.y89[[3]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mCont.y89[[4]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mCont.y89[[5]] <- summary (felm (pbega2 ~ n50_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mCont.y89[[6]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  
  # (i.iv) Arab Spring
  mCont.aspring[[1]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mCont.aspring[[2]] <- summary (felm (pbega2 ~ n50_d90_wequal_any | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mCont.aspring[[3]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mCont.aspring[[4]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mCont.aspring[[5]] <- summary (felm (pbega2 ~ n50_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mCont.aspring[[6]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  
  # (i.v) excluding borderline protests
  mCont.border[[1]] <- summary (felm (pbega2 ~ n50_d45_wequal_border | countryYear | 0 | country, data=base))$coef
  mCont.border[[2]] <- summary (felm (pbega2 ~ n50_d90_wequal_border | countryYear | 0 | country, data=base))$coef
  mCont.border[[3]] <- summary (felm (pbega2 ~ n50_d45_wequal_border | countryYear | 0 | country, data=base))$coef
  mCont.border[[4]] <- summary (felm (pbega2 ~ n50_d120_wequal_border + ele30 | countryYear | 0 | country, data=base))$coef
  mCont.border[[5]] <- summary (felm (pbega2 ~ n50_d90_wequal_border + ele30 | countryYear | 0 | country, data=base))$coef
  mCont.border[[6]] <- summary (felm (pbega2 ~ n50_d120_wequal_border + ele30 | countryYear | 0 | country, data=base))$coef
  
  # (i.vi) autocracies only (Polity)
  mCont.aut[[1]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mCont.aut[[2]] <- summary (felm (pbega2 ~ n50_d90_wequal_any | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mCont.aut[[3]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mCont.aut[[4]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mCont.aut[[5]] <- summary (felm (pbega2 ~ n50_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mCont.aut[[6]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  
  # (i.vii) autocracies only (V-Dem)
  mCont.autVD[[1]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mCont.autVD[[2]] <- summary (felm (pbega2 ~ n50_d90_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mCont.autVD[[3]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mCont.autVD[[4]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mCont.autVD[[5]] <- summary (felm (pbega2 ~ n50_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mCont.autVD[[6]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  
  # (i.viii) democracies only (Polity)
  mCont.dem[[1]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mCont.dem[[2]] <- summary (felm (pbega2 ~ n50_d90_wequal_any | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mCont.dem[[3]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mCont.dem[[4]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mCont.dem[[5]] <- summary (felm (pbega2 ~ n50_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mCont.dem[[6]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  
  # (i.ix) democracies only (V-Dem)
  mCont.demVD[[1]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mCont.demVD[[2]] <- summary (felm (pbega2 ~ n50_d90_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mCont.demVD[[3]] <- summary (felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mCont.demVD[[4]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mCont.demVD[[5]] <- summary (felm (pbega2 ~ n50_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mCont.demVD[[6]] <- summary (felm (pbega2 ~ n50_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  
  
  ## (ii) 800km neighbors
  
  # (ii.i) Internet era
  mN800.int[[1]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mN800.int[[2]] <- summary (felm (pbega2 ~ n800_d90_wequal_any | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mN800.int[[3]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mN800.int[[4]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mN800.int[[5]] <- summary (felm (pbega2 ~ n800_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mN800.int[[6]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  
  # (ii.ii) fall of Communism
  mN800.pc[[1]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mN800.pc[[2]] <- summary (felm (pbega2 ~ n800_d90_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mN800.pc[[3]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mN800.pc[[4]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mN800.pc[[5]] <- summary (felm (pbega2 ~ n800_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mN800.pc[[6]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  
  # (ii.iii) 1989 only
  mN800.y89[[1]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mN800.y89[[2]] <- summary (felm (pbega2 ~ n800_d90_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mN800.y89[[3]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mN800.y89[[4]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mN800.y89[[5]] <- summary (felm (pbega2 ~ n800_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mN800.y89[[6]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  
  # (ii.iv) Arab Spring
  mN800.aspring[[1]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mN800.aspring[[2]] <- summary (felm (pbega2 ~ n800_d90_wequal_any | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mN800.aspring[[3]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mN800.aspring[[4]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mN800.aspring[[5]] <- summary (felm (pbega2 ~ n800_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mN800.aspring[[6]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  
  # (ii.v) excluding borderline protests
  mN800.border[[1]] <- summary (felm (pbega2 ~ n800_d45_wequal_border | countryYear | 0 | country, data=base))$coef
  mN800.border[[2]] <- summary (felm (pbega2 ~ n800_d90_wequal_border | countryYear | 0 | country, data=base))$coef
  mN800.border[[3]] <- summary (felm (pbega2 ~ n800_d45_wequal_border | countryYear | 0 | country, data=base))$coef
  mN800.border[[4]] <- summary (felm (pbega2 ~ n800_d120_wequal_border + ele30 | countryYear | 0 | country, data=base))$coef
  mN800.border[[5]] <- summary (felm (pbega2 ~ n800_d90_wequal_border + ele30 | countryYear | 0 | country, data=base))$coef
  mN800.border[[6]] <- summary (felm (pbega2 ~ n800_d120_wequal_border + ele30 | countryYear | 0 | country, data=base))$coef
  
  # (ii.vi) autocracies only (Polity)
  mN800.aut[[1]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mN800.aut[[2]] <- summary (felm (pbega2 ~ n800_d90_wequal_any | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mN800.aut[[3]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mN800.aut[[4]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mN800.aut[[5]] <- summary (felm (pbega2 ~ n800_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mN800.aut[[6]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  
  # (ii.vii) autocracies only (V-Dem)
  mN800.autVD[[1]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mN800.autVD[[2]] <- summary (felm (pbega2 ~ n800_d90_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mN800.autVD[[3]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mN800.autVD[[4]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mN800.autVD[[5]] <- summary (felm (pbega2 ~ n800_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mN800.autVD[[6]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  
  # (ii.viii) democracies only (Polity)
  mN800.dem[[1]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mN800.dem[[2]] <- summary (felm (pbega2 ~ n800_d90_wequal_any | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mN800.dem[[3]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mN800.dem[[4]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mN800.dem[[5]] <- summary (felm (pbega2 ~ n800_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mN800.dem[[6]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  
  # (ii.ix) democracies only (V-Dem)
  mN800.demVD[[1]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mN800.demVD[[2]] <- summary (felm (pbega2 ~ n800_d90_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mN800.demVD[[3]] <- summary (felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mN800.demVD[[4]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mN800.demVD[[5]] <- summary (felm (pbega2 ~ n800_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mN800.demVD[[6]] <- summary (felm (pbega2 ~ n800_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  
  
  ## (iii) UN region neighbors
  
  # (iii.i) Internet era
  mUNReg.int[[1]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mUNReg.int[[2]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mUNReg.int[[3]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mUNReg.int[[4]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mUNReg.int[[5]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  mUNReg.int[[6]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1995-10-24",]))$coef
  
  # (iii.ii) fall of Communism
  mUNReg.pc[[1]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mUNReg.pc[[2]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mUNReg.pc[[3]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mUNReg.pc[[4]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mUNReg.pc[[5]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  mUNReg.pc[[6]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1992-12-31",]))$coef
  
  # (iii.iii) 1989 only
  mUNReg.y89[[1]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mUNReg.y89[[2]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mUNReg.y89[[3]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mUNReg.y89[[4]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mUNReg.y89[[5]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  mUNReg.y89[[6]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="1989-01-01" & base$date<="1989-12-31",]))$coef
  
  # (iii.iv) Arab Spring
  mUNReg.aspring[[1]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mUNReg.aspring[[2]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mUNReg.aspring[[3]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mUNReg.aspring[[4]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mUNReg.aspring[[5]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  mUNReg.aspring[[6]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$date>="2010-01-01" & base$date<="2011-12-31",]))$coef
  
  # (iii.v) excluding borderline protests
  mUNReg.border[[1]] <- summary (felm (pbega2 ~ nUN_d45_wequal_border | countryYear | 0 | country, data=base))$coef
  mUNReg.border[[2]] <- summary (felm (pbega2 ~ nUN_d90_wequal_border | countryYear | 0 | country, data=base))$coef
  mUNReg.border[[3]] <- summary (felm (pbega2 ~ nUN_d45_wequal_border | countryYear | 0 | country, data=base))$coef
  mUNReg.border[[4]] <- summary (felm (pbega2 ~ nUN_d120_wequal_border + ele30 | countryYear | 0 | country, data=base))$coef
  mUNReg.border[[5]] <- summary (felm (pbega2 ~ nUN_d90_wequal_border + ele30 | countryYear | 0 | country, data=base))$coef
  mUNReg.border[[6]] <- summary (felm (pbega2 ~ nUN_d120_wequal_border + ele30 | countryYear | 0 | country, data=base))$coef
  
  # (iii.vi) autocracies only (Polity)
  mUNReg.aut[[1]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mUNReg.aut[[2]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mUNReg.aut[[3]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mUNReg.aut[[4]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mUNReg.aut[[5]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  mUNReg.aut[[6]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==1,]))$coef
  
  # (iii.vii) autocracies only (V-Dem)
  mUNReg.autVD[[1]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mUNReg.autVD[[2]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mUNReg.autVD[[3]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mUNReg.autVD[[4]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mUNReg.autVD[[5]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  mUNReg.autVD[[6]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==1,]))$coef
  
  # (iii.viii) democracies only (Polity)
  mUNReg.dem[[1]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mUNReg.dem[[2]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mUNReg.dem[[3]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mUNReg.dem[[4]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mUNReg.dem[[5]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  mUNReg.dem[[6]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracy==0,]))$coef
  
  # (iii.ix) democracies only (V-Dem)
  mUNReg.demVD[[1]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mUNReg.demVD[[2]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mUNReg.demVD[[3]] <- summary (felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mUNReg.demVD[[4]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mUNReg.demVD[[5]] <- summary (felm (pbega2 ~ nUN_d90_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
  mUNReg.demVD[[6]] <- summary (felm (pbega2 ~ nUN_d120_wequal_any + ele30 | countryYear | 0 | country, data=base[base$autocracyVDem==0,]))$coef
}
)  ## 1418 seconds





########## (3) APPENDICES

### (3.1) Descriptive statistics

## (3.1.1) Replicating the data reported in Table A19: Data Overview (Weekly)

# (a) contiguous neighbors
(tweekCont04 <- with (bweek, prop.table (table (pbega, n50_d30_wequal_any), 2))*100)
(tweekCont06 <- with (bweek, prop.table (table (pbega, n50_d45_wequal_any), 2))*100)
(tweekCont12 <- with (bweek, prop.table (table (pbega, n50_d90_wequal_any), 2))*100)
(tweekCont18 <- with (bweek, prop.table (table (pbega, n50_d120_wequal_any), 2))*100)

(tweekCont04abs <- with (bweek, table (pbega, n50_d30_wequal_any)))
(tweekCont06abs <- with (bweek, table (pbega, n50_d45_wequal_any)))
(tweekCont12abs <- with (bweek, table (pbega, n50_d90_wequal_any)))
(tweekCont18abs <- with (bweek, table (pbega, n50_d120_wequal_any)))

# t-tests
(tvalWeekCont04 <- t.test (x=bweek[bweek$n50_d30_wequal_any==0,]$pbega, y=bweek[bweek$n50_d30_wequal_any==1,]$pbega))
(tvalWeekCont06 <- t.test (x=bweek[bweek$n50_d45_wequal_any==0,]$pbega, y=bweek[bweek$n50_d45_wequal_any==1,]$pbega))
(tvalWeekCont12 <- t.test (x=bweek[bweek$n50_d90_wequal_any==0,]$pbega, y=bweek[bweek$n50_d90_wequal_any==1,]$pbega))
(tvalWeekCont18 <- t.test (x=bweek[bweek$n50_d120_wequal_any==0,]$pbega, y=bweek[bweek$n50_d120_wequal_any==1,]$pbega))

# (b) 800km neighbors
(tweekN800.04 <- with (bweek, prop.table (table (pbega, n800_d30_wequal_any), 2))*100)
(tweekN800.06 <- with (bweek, prop.table (table (pbega, n800_d45_wequal_any), 2))*100)
(tweekN800.12 <- with (bweek, prop.table (table (pbega, n800_d90_wequal_any), 2))*100)
(tweekN800.18 <- with (bweek, prop.table (table (pbega, n800_d120_wequal_any), 2))*100)

(tweekN800.04abs <- with (bweek, table (pbega, n800_d30_wequal_any)))
(tweekN800.06abs <- with (bweek, table (pbega, n800_d45_wequal_any)))
(tweekN800.12abs <- with (bweek, table (pbega, n800_d90_wequal_any)))
(tweekN800.18abs <- with (bweek, table (pbega, n800_d120_wequal_any)))

# t-tests
(tvalWeekN800.04 <- t.test (x=bweek[bweek$n800_d30_wequal_any==0,]$pbega, y=bweek[bweek$n800_d30_wequal_any==1,]$pbega))
(tvalWeekN800.06 <- t.test (x=bweek[bweek$n800_d45_wequal_any==0,]$pbega, y=bweek[bweek$n800_d45_wequal_any==1,]$pbega))
(tvalWeekN800.12 <- t.test (x=bweek[bweek$n800_d90_wequal_any==0,]$pbega, y=bweek[bweek$n800_d90_wequal_any==1,]$pbega))
(tvalWeekN800.18 <- t.test (x=bweek[bweek$n800_d120_wequal_any==0,]$pbega, y=bweek[bweek$n800_d120_wequal_any==1,]$pbega))

# (c) UN region neighbors
(tweekUNReg04 <- with (bweek, prop.table (table (pbega, nUN_d30_wequal_any), 2))*100)
(tweekUNReg06 <- with (bweek, prop.table (table (pbega, nUN_d45_wequal_any), 2))*100)
(tweekUNReg12 <- with (bweek, prop.table (table (pbega, nUN_d90_wequal_any), 2))*100)
(tweekUNReg18 <- with (bweek, prop.table (table (pbega, nUN_d120_wequal_any), 2))*100)

(tweekUNReg04abs <- with (bweek, table (pbega, nUN_d30_wequal_any)))
(tweekUNReg06abs <- with (bweek, table (pbega, nUN_d45_wequal_any)))
(tweekUNReg12abs <- with (bweek, table (pbega, nUN_d90_wequal_any)))
(tweekUNReg18abs <- with (bweek, table (pbega, nUN_d120_wequal_any)))

# t-tests
(tvalWeekUNReg04 <- t.test (x=bweek[bweek$nUN_d30_wequal_any==0,]$pbega, y=bweek[bweek$nUN_d30_wequal_any==1,]$pbega))
(tvalWeekUNReg06 <- t.test (x=bweek[bweek$nUN_d45_wequal_any==0,]$pbega, y=bweek[bweek$nUN_d45_wequal_any==1,]$pbega))
(tvalWeekUNReg12 <- t.test (x=bweek[bweek$nUN_d90_wequal_any==0,]$pbega, y=bweek[bweek$nUN_d90_wequal_any==1,]$pbega))
(tvalWeekUNReg18 <- t.test (x=bweek[bweek$nUN_d120_wequal_any==0,]$pbega, y=bweek[bweek$nUN_d120_wequal_any==1,]$pbega))


## (3.1.2) Replicating the data reported in Table A28: Data Overview (Monthly)

# (a) contiguous neighbors
(tmonthCont01 <- with (bmonth, prop.table (table (pbega, n50_d30_wequal_any), 2))*100)
(tmonthCont02 <- with (bmonth, prop.table (table (pbega, n50_d45_wequal_any), 2))*100)
(tmonthCont03 <- with (bmonth, prop.table (table (pbega, n50_d90_wequal_any), 2))*100)
(tmonthCont04 <- with (bmonth, prop.table (table (pbega, n50_d120_wequal_any), 2))*100)

(tmonthCont01abs <- with (bmonth, table (pbega, n50_d30_wequal_any)))
(tmonthCont02abs <- with (bmonth, table (pbega, n50_d45_wequal_any)))
(tmonthCont03abs <- with (bmonth, table (pbega, n50_d90_wequal_any)))
(tmonthCont04abs <- with (bmonth, table (pbega, n50_d120_wequal_any)))

# t-tests
(tvalMonthCont01 <- t.test (x=bmonth[bmonth$n50_d30_wequal_any==0,]$pbega, y=bmonth[bmonth$n50_d30_wequal_any==1,]$pbega))
(tvalMonthCont02 <- t.test (x=bmonth[bmonth$n50_d45_wequal_any==0,]$pbega, y=bmonth[bmonth$n50_d45_wequal_any==1,]$pbega))
(tvalMonthCont03 <- t.test (x=bmonth[bmonth$n50_d90_wequal_any==0,]$pbega, y=bmonth[bmonth$n50_d90_wequal_any==1,]$pbega))
(tvalMonthCont04 <- t.test (x=bmonth[bmonth$n50_d120_wequal_any==0,]$pbega, y=bmonth[bmonth$n50_d120_wequal_any==1,]$pbega))

# (b) 800km neighbors
(tmonthN800.01 <- with (bmonth, prop.table (table (pbega, n800_d30_wequal_any), 2))*100)
(tmonthN800.02 <- with (bmonth, prop.table (table (pbega, n800_d45_wequal_any), 2))*100)
(tmonthN800.03 <- with (bmonth, prop.table (table (pbega, n800_d90_wequal_any), 2))*100)
(tmonthN800.04 <- with (bmonth, prop.table (table (pbega, n800_d120_wequal_any), 2))*100)

(tmonthN800.01abs <- with (bmonth, table (pbega, n800_d30_wequal_any)))
(tmonthN800.02abs <- with (bmonth, table (pbega, n800_d45_wequal_any)))
(tmonthN800.03abs <- with (bmonth, table (pbega, n800_d90_wequal_any)))
(tmonthN800.04abs <- with (bmonth, table (pbega, n800_d120_wequal_any)))

# t-tests
(tvalMonthN800.01 <- t.test (x=bmonth[bmonth$n800_d30_wequal_any==0,]$pbega, y=bmonth[bmonth$n800_d30_wequal_any==1,]$pbega))
(tvalMonthN800.02 <- t.test (x=bmonth[bmonth$n800_d45_wequal_any==0,]$pbega, y=bmonth[bmonth$n800_d45_wequal_any==1,]$pbega))
(tvalMonthN800.03 <- t.test (x=bmonth[bmonth$n800_d90_wequal_any==0,]$pbega, y=bmonth[bmonth$n800_d90_wequal_any==1,]$pbega))
(tvalMonthN800.04 <- t.test (x=bmonth[bmonth$n800_d120_wequal_any==0,]$pbega, y=bmonth[bmonth$n800_d120_wequal_any==1,]$pbega))

# (c) UN region neighbors
(tmonthUNReg01 <- with (bmonth, prop.table (table (pbega, nUN_d30_wequal_any), 2))*100)
(tmonthUNReg02 <- with (bmonth, prop.table (table (pbega, nUN_d45_wequal_any), 2))*100)
(tmonthUNReg03 <- with (bmonth, prop.table (table (pbega, nUN_d90_wequal_any), 2))*100)
(tmonthUNReg04 <- with (bmonth, prop.table (table (pbega, nUN_d120_wequal_any), 2))*100)

(tmonthUNReg01abs <- with (bmonth, table (pbega, nUN_d30_wequal_any)))
(tmonthUNReg02abs <- with (bmonth, table (pbega, nUN_d45_wequal_any)))
(tmonthUNReg03abs <- with (bmonth, table (pbega, nUN_d90_wequal_any)))
(tmonthUNReg04abs <- with (bmonth, table (pbega, nUN_d120_wequal_any)))

# t-tests
(tvalMonthUNReg01 <- t.test (x=bmonth[bmonth$nUN_d30_wequal_any==0,]$pbega, y=bmonth[bmonth$nUN_d30_wequal_any==1,]$pbega))
(tvalMonthUNReg02 <- t.test (x=bmonth[bmonth$nUN_d45_wequal_any==0,]$pbega, y=bmonth[bmonth$nUN_d45_wequal_any==1,]$pbega))
(tvalMonthUNReg03 <- t.test (x=bmonth[bmonth$nUN_d90_wequal_any==0,]$pbega, y=bmonth[bmonth$nUN_d90_wequal_any==1,]$pbega))
(tvalMonthUNReg04 <- t.test (x=bmonth[bmonth$nUN_d120_wequal_any==0,]$pbega, y=bmonth[bmonth$nUN_d120_wequal_any==1,]$pbega))


## (3.1.3) Replicating the data reported in Table A378: Data Overview (Yearly)

# (a) contiguous neighbors
(tyearCont01 <- with (byear, prop.table (table (pbega, n50_y01_wequal_any), 2))*100)
(tyearCont01abs <- with (byear, table (pbega, n50_y01_wequal_any)))
(tvalYearCont01 <- t.test (x=byear[byear$n50_y01_wequal_any==0,]$pbega, y=byear[byear$n50_y01_wequal_any==1,]$pbega))

# (b) 800km neighbors
(tyearN800.01 <- with (byear, prop.table (table (pbega, n800_y01_wequal_any), 2))*100)
(tyearN800.01abs <- with (byear, table (pbega, n800_y01_wequal_any)))
(tvalYearN800.01 <- t.test (x=byear[byear$n800_y01_wequal_any==0,]$pbega, y=byear[byear$n800_y01_wequal_any==1,]$pbega))

# (c) UN region neighbors
(tyearUNReg01 <- with (byear, prop.table (table (pbega, nUN_y01_wequal_any), 2))*100)
(tyearUNReg01abs <- with (byear, table (pbega, nUN_y01_wequal_any)))
(tvalYearUNReg01 <- t.test (x=byear[byear$nUN_y01_wequal_any==0,]$pbega, y=byear[byear$nUN_y01_wequal_any==1,]$pbega))



### (3.2) Statistical analysis

## (3.2.1) Preparing the data still further

# (a) GDELT data
gdelt$year <- as.numeric (format (gdelt$date, "%Y"))
gdelt$countryYear <- with (gdelt, factor (paste (country, year, sep="_")))
gdelt$pbeg_gdelt2 <- gdelt$pbeg_gdelt*100
gdelt$wdi_GDPcap_lag <- log (gdelt$wdi_GDPcap_lag)
gdelt$pop_lag <- log (gdelt$pop_lag)

# (b) SPEED data
speed$year <- as.numeric (format (speed$date, "%Y"))
speed$countryYear <- with (speed, factor (paste (country, year, sep="_")))
speed$pbegSpeed2 <- speed$pbegSpeed*100
speed$wdi_GDPcap_lag <- log (speed$wdi_GDPcap_lag)
speed$pop_lag <- log (speed$pop_lag)

# (c) MMD data (Clark and Regan 2015)
mmd$year <- as.numeric (format (mmd$date, "%Y"))
mmd$countryYear <- with (mmd, factor (paste (country, year, sep="_")))
mmd$pbegMMD2 <- mmd$pbegMMD*100
mmd$wdi_GDPcap_lag <- log (mmd$wdi_GDPcap_lag)
mmd$pop_lag <- log (mmd$pop_lag)

# (d) Bunce data

# merging the datasets and recoding some variables
base <- merge (base, bunce, by.x="id", by.y="id", all.x=T, all.y=F)

# protest success (excluding cases of non-genuine accomodation)
base$n50_dEle_wSuc2_any2 <- factor (with (base, ifelse (
  n50_dEle_wSuc2_any==0 & n50_dEle_wunSuc2_any==0, "option1-no protests", ifelse (
    n50_dEle_wSuc2_any==1 & n50_dEle_wunSuc2_any==0, "option2-all successful", ifelse (
      n50_dEle_wSuc2_any==1 & n50_dEle_wunSuc2_any==1, "option3-some successful", "option4-none successful")))))
base$n50_dEle_wSucpost2_any2 <- factor (with (base, ifelse (
  n50_dEle_wSucpost2_any==0 & n50_dEle_wunSucpost2_any==0, "option1-no protests", ifelse (n50_dEle_wSucpost2_any==1 & n50_dEle_wunSucpost2_any==0, "option2-all successful", ifelse (
    n50_dEle_wSucpost2_any==1 & n50_dEle_wunSucpost2_any==1, "option3-some successful", "option4-none successful")))))
base$n50_dEle_wSucnear2_any2 <- factor (with (base, ifelse (
  n50_dEle_wunSucnear2_any==0 & n50_d120_wunSuc2_any==0, "option1-no protests", ifelse (
    n50_dEle_wunSucnear2_any==1 & n50_d120_wunSuc2_any==0, "option2-all successful", ifelse (
      n50_dEle_wunSucnear2_any==1 & n50_d120_wunSuc2_any==1, "option3-some successful", "option4-none successful")))))
base$n800_dEle_wSuc2_any2 <- factor (with (base, ifelse (
  n800_dEle_wSuc2_any==0 & n800_dEle_wunSuc2_any==0, "option1-no protests", ifelse (
    n800_dEle_wSuc2_any==1 & n800_dEle_wunSuc2_any==0, "option2-all successful", ifelse (
      n800_dEle_wSuc2_any==1 & n800_dEle_wunSuc2_any==1, "option3-some successful", "option4-none successful")))))
base$n800_dEle_wSucpost2_any2 <- factor (with (base, ifelse (
  n800_dEle_wSucpost2_any==0 & n800_dEle_wunSucpost2_any==0, "option1-no protests", ifelse (
    n800_dEle_wSucpost2_any==1 & n800_dEle_wunSucpost2_any==0, "option2-all successful", ifelse (
      n800_dEle_wSucpost2_any==1 & n800_dEle_wunSucpost2_any==1, "option3-some successful", "option4-none successful")))))
base$n800_dEle_wSucnear2_any2 <- factor (with (base, ifelse (
  n800_dEle_wunSucnear2_any==0 & n800_d120_wunSuc2_any==0, "option1-no protests", ifelse (
    n800_dEle_wunSucnear2_any==1 & n800_d120_wunSuc2_any==0, "option2-all successful", ifelse (
      n800_dEle_wunSucnear2_any==1 & n800_d120_wunSuc2_any==1, "option3-some successful", "option4-none successful")))))
base$nUN_dEle_wSuc2_any2 <- factor (with (base, ifelse (
  nUN_dEle_wSuc2_any==0 & nUN_dEle_wunSuc2_any==0, "option1-no protests", ifelse (
    nUN_dEle_wSuc2_any==1 & nUN_dEle_wunSuc2_any==0, "option2-all successful", ifelse (
      nUN_dEle_wSuc2_any==1 & nUN_dEle_wunSuc2_any==1, "option3-some successful", "option4-none successful")))))
base$nUN_dEle_wSucpost2_any2 <- factor (with (base, ifelse (
  nUN_dEle_wSucpost2_any==0 & nUN_dEle_wunSucpost2_any==0, "option1-no protests", ifelse (
    nUN_dEle_wSucpost2_any==1 & nUN_dEle_wunSucpost2_any==0, "option2-all successful", ifelse (
      nUN_dEle_wSucpost2_any==1 & nUN_dEle_wunSucpost2_any==1, "option3-some successful", "option4-none successful")))))
base$nUN_dEle_wSucnear2_any2 <- factor (with (base, ifelse (
  nUN_dEle_wunSucnear2_any==0 & nUN_d120_wunSuc2_any==0, "option1-no protests", ifelse (
    nUN_dEle_wunSucnear2_any==1 & nUN_d120_wunSuc2_any==0, "option2-all successful", ifelse (
      nUN_dEle_wunSucnear2_any==1 & nUN_d120_wunSuc2_any==1, "option3-some successful", "option4-none successful")))))

# government repression
base$n50_dEle_wRepr_any2 <- factor (with (base, ifelse (
  n50_dEle_wRepr_any==0 & n50_dEle_wunRepr_any==0, "option1-no protests", ifelse (
    n50_dEle_wRepr_any==1 & n50_dEle_wunRepr_any==0, "option2-all repressed", ifelse (
      n50_dEle_wRepr_any==1 & n50_dEle_wunRepr_any==1, "option3-some repressed", "option4-none repressed")))))
base$n50_dEle_wReprpost2_any2 <- factor (with (base, ifelse (
  n50_dEle_wReprpost2_any==0 & n50_dEle_wunReprpost2_any==0, "option1-no protests", ifelse (
    n50_dEle_wReprpost2_any==1 & n50_dEle_wunReprpost2_any==0, "option2-all repressed", ifelse (
      n50_dEle_wReprpost2_any==1 & n50_dEle_wunReprpost2_any==1, "option3-some repressed", "option4-none repressed")))))
base$n50_dEle_wReprnear2_any2 <- factor (with (base, ifelse (
  n50_dEle_wReprnear2_any==0 & n50_dEle_wunReprnear2_any==0, "option1-no protests", ifelse (
    n50_dEle_wReprnear2_any==1 & n50_dEle_wunReprnear2_any==0, "option2-all repressed", ifelse (
      n50_dEle_wReprnear2_any==1 & n50_dEle_wunReprnear2_any==1, "option3-some repressed", "option4-none repressed")))))
base$n800_dEle_wRepr_any2 <- factor (with (base, ifelse (
  n800_dEle_wRepr_any==0 & n800_dEle_wunRepr_any==0, "option1-no protests", ifelse (
    n800_dEle_wRepr_any==1 & n800_dEle_wunRepr_any==0, "option2-all repressed", ifelse (
      n800_dEle_wRepr_any==1 & n800_dEle_wunRepr_any==1, "option3-some repressed", "option4-none repressed")))))
base$n800_dEle_wReprpost2_any2 <- factor (with (base, ifelse (
  n800_dEle_wReprpost2_any==0 & n800_dEle_wunReprpost2_any==0, "option1-no protests", ifelse (
    n800_dEle_wReprpost2_any==1 & n800_dEle_wunReprpost2_any==0, "option2-all repressed", ifelse (
      n800_dEle_wReprpost2_any==1 & n800_dEle_wunReprpost2_any==1, "option3-some repressed", "option4-none repressed")))))
base$n800_dEle_wReprnear2_any2 <- factor (with (base, ifelse (
  n800_dEle_wReprnear2_any==0 & n800_dEle_wunReprnear2_any==0, "option1-no protests", ifelse (
    n800_dEle_wReprnear2_any==1 & n800_dEle_wunReprnear2_any==0, "option2-all repressed", ifelse (
      n800_dEle_wReprnear2_any==1 & n800_dEle_wunReprnear2_any==1, "option3-some repressed", "option4-none repressed")))))
base$nUN_dEle_wRepr_any2 <- factor (with (base, ifelse (
  nUN_dEle_wRepr_any==0 & nUN_dEle_wunRepr_any==0, "option1-no protests", ifelse (
    nUN_dEle_wRepr_any==1 & nUN_dEle_wunRepr_any==0, "option2-all repressed", ifelse (
      nUN_dEle_wRepr_any==1 & nUN_dEle_wunRepr_any==1, "option3-some repressed", "option4-none repressed")))))
base$nUN_dEle_wReprpost2_any2 <- factor (with (base, ifelse (
  nUN_dEle_wReprpost2_any==0 & nUN_dEle_wunReprpost2_any==0, "option1-no protests", ifelse (
    nUN_dEle_wReprpost2_any==1 & nUN_dEle_wunReprpost2_any==0, "option2-all repressed", ifelse (
      nUN_dEle_wReprpost2_any==1 & nUN_dEle_wunReprpost2_any==1, "option3-some repressed", "option4-none repressed")))))
base$nUN_dEle_wReprnear2_any2 <- factor (with (base, ifelse (
  nUN_dEle_wReprnear2_any==0 & nUN_dEle_wunReprnear2_any==0, "option1-no protests", ifelse (
    nUN_dEle_wReprnear2_any==1 & nUN_dEle_wunReprnear2_any==0, "option2-all repressed", ifelse (
      nUN_dEle_wReprnear2_any==1 & nUN_dEle_wunReprnear2_any==1, "option3-some repressed", "option4-none repressed")))))

# (e) weekly data
bweek$pbega2 <- bweek$pbega*100
bweek$wdi_GDPcap_lag <- log (bweek$wdi_GDPcap_lag)
bweek$gdp_lag <- log (bweek$gdp_lag)
bweek$pop_lag <- log (bweek$pop_lag)

# (f) monthly data
bmonth$pbega2 <- bmonth$pbega*100
bmonth$wdi_GDPcap_lag <- log (bmonth$wdi_GDPcap_lag)
bmonth$gdp_lag <- log (bmonth$gdp_lag)
bmonth$pop_lag <- log (bmonth$pop_lag)

# (g) yearly data
byear$pbega2 <- byear$pbega*100
byear$wdi_GDPcap_lag <- log (byear$wdi_GDPcap_lag)
byear$gdp_lag <- log (byear$gdp_lag)
byear$pop_lag <- log (byear$pop_lag)

# (h) Arab Spring data
bspring$pbega2 <- bspring$pbega*100
bspring$wdi_GDPcap_lag <- log (bspring$wdi_GDPcap_lag)
bspring$gdp_lag <- log (bspring$gdp_lag)
bspring$pop_lag <- log (bspring$pop_lag)

# (i) MENA-only sample
bmena$pbega2 <- bmena$pbega*100
bmena$wdi_GDPcap_lag <- log (bmena$wdi_GDPcap_lag)
bmena$gdp_lag <- log (bmena$gdp_lag)
bmena$pop_lag <- log (bmena$pop_lag)

# (j) Venezuela data
vzla$year <- as.numeric (format (vzla$date, "%Y"))
vzla$countryYear <- with (vzla, factor (paste (country, year, sep="_")))
vzla$pbega2 <- vzla$pbega*100
vzla$wdi_GDPcap_lag <- log (vzla$wdi_GDPcap_lag)
vzla$pop_lag <- log (vzla$pop_lag)



## (3.2.2) Models with interactions

# listing the explanatory variables
vContRob01 <- c ("n50_d45_wequal_any", "n50_d90_wequal_any", "n50_d120_wequal_any"
                 , "n50_d45_wequal_sum", "n50_d90_wequal_sum", "n50_d120_wequal_sum"
                 , "n50_d45_wSize_any", "n50_d90_wSize_any", "n50_d120_wSize_any"
                 , "n50_d45_wSuc_any2", "n50_d90_wSuc_any2", "n50_d120_wSuc_any2"
                 , "n50_d45_wRepr_any2", "n50_d90_wRepr_any2", "n50_d120_wRepr_any2"
                 , "n50_d45_wElec_any", "n50_d90_wElec_any", "n50_d120_wElec_any")
vN800Rob01 <- c ("n800_d45_wequal_any", "n800_d90_wequal_any", "n800_d120_wequal_any"
                 , "n800_d45_wequal_sum", "n800_d90_wequal_sum", "n800_d120_wequal_sum"
                 , "n800_d45_wSize_any", "n800_d90_wSize_any", "n800_d120_wSize_any"
                 , "n800_d45_wSuc_any2", "n800_d90_wSuc_any2", "n800_d120_wSuc_any2"
                 , "n800_d45_wRepr_any2", "n800_d90_wRepr_any2", "n800_d120_wRepr_any2"
                 , "n800_d45_wElec_any", "n800_d90_wElec_any", "n800_d120_wElec_any")
vUNRegRob01 <- c ("nUN_d45_wequal_any", "nUN_d90_wequal_any", "nUN_d120_wequal_any"
                  , "nUN_d45_wequal_sum", "nUN_d90_wequal_sum", "nUN_d120_wequal_sum"
                  , "nUN_d45_wSize_any", "nUN_d90_wSize_any", "nUN_d120_wSize_any"
                  , "nUN_d45_wSuc_any2", "nUN_d90_wSuc_any2", "nUN_d120_wSuc_any2"
                  , "nUN_d45_wRepr_any2", "nUN_d90_wRepr_any2", "nUN_d120_wRepr_any2"
                  , "nUN_d45_wElec_any", "nUN_d90_wElec_any", "nUN_d120_wElec_any")

# running one model to get the number of observations

# variation in missing values
nrow (base[!is.na (base$ele30),]); nrow (base[!is.na (base$wdi_InternetUsers_lag),]); nrow (base[!is.na (base$wdi_GDPcapGrowth_lag),]); nrow (base[!is.na (base$physint_lag),])  ## low: internet users; high:elections

# fitting the models
(sumNobsContRob01a.high <- summary (NobsContRob01a.high <- felm (pbega2 ~ n50_d45_wequal_any*ele30 | 0 | 0 | 0, data=base)))
(sumNobsContRob01b.high <- summary (NobsContRob01b.high <- felm (pbega2 ~ n50_d45_wequal_any*ele30 | countryYear | 0 | 0, data=base)))
(sumNobsContRob01c.high <- summary (NobsContRob01c.high <- felm (pbega2 ~ n50_d45_wequal_any*ele30 | 0 | 0 | country, data=base)))
(sumNobsContRob01d.high <- summary (NobsContRob01d.high <- felm (pbega2 ~ n50_d45_wequal_any*ele30 | countryYear | 0 | country, data=base)))
(sumNobsContRob01a.low <- summary (NobsContRob01a.low <- felm (pbega2 ~ n50_d45_wequal_any*wdi_InternetUsers_lag | 0 | 0 | 0, data=base)))
(sumNobsContRob01b.low <- summary (NobsContRob01b.low <- felm (pbega2 ~ n50_d45_wequal_any*wdi_InternetUsers_lag | countryYear | 0 | 0, data=base)))
(sumNobsContRob01c.low <- summary (NobsContRob01c.low <- felm (pbega2 ~ n50_d45_wequal_any*wdi_InternetUsers_lag | 0 | 0 | country, data=base)))
(sumNobsContRob01d.low <- summary (NobsContRob01d.low <- felm (pbega2 ~ n50_d45_wequal_any*wdi_InternetUsers_lag | countryYear | 0 | country, data=base)))

(sumNobsN800Rob01a.high <- summary (NobsN800Rob01a.high <- felm (pbega2 ~ n800_d45_wequal_any*ele30 | 0 | 0 | 0, data=base)))
(sumNobsN800Rob01b.high <- summary (NobsN800Rob01b.high <- felm (pbega2 ~ n800_d45_wequal_any*ele30 | countryYear | 0 | 0, data=base)))
(sumNobsN800Rob01c.high <- summary (NobsN800Rob01c.high <- felm (pbega2 ~ n800_d45_wequal_any*ele30 | 0 | 0 | country, data=base)))
(sumNobsN800Rob01d.high <- summary (NobsN800Rob01d.high <- felm (pbega2 ~ n800_d45_wequal_any*ele30 | countryYear | 0 | country, data=base)))
(sumNobsN800Rob01a.low <- summary (NobsN800Rob01a.low <- felm (pbega2 ~ n800_d45_wequal_any*wdi_InternetUsers_lag | 0 | 0 | 0, data=base)))
(sumNobsN800Rob01b.low <- summary (NobsN800Rob01b.low <- felm (pbega2 ~ n800_d45_wequal_any*wdi_InternetUsers_lag | countryYear | 0 | 0, data=base)))
(sumNobsN800Rob01c.low <- summary (NobsN800Rob01c.low <- felm (pbega2 ~ n800_d45_wequal_any*wdi_InternetUsers_lag | 0 | 0 | country, data=base)))
(sumNobsN800Rob01d.low <- summary (NobsN800Rob01d.low <- felm (pbega2 ~ n800_d45_wequal_any*wdi_InternetUsers_lag | countryYear | 0 | country, data=base)))

(sumNobsUNRegRob01a.high <- summary (NobsUNRegRob01a.high <- felm (pbega2 ~ nUN_d45_wequal_any*ele30 | 0 | 0 | 0, data=base)))
(sumNobsUNRegRob01b.high <- summary (NobsUNRegRob01b.high <- felm (pbega2 ~ nUN_d45_wequal_any*ele30 | countryYear | 0 | 0, data=base)))
(sumNobsUNRegRob01c.high <- summary (NobsUNRegRob01c.high <- felm (pbega2 ~ nUN_d45_wequal_any*ele30 | 0 | 0 | country, data=base)))
(sumNobsUNRegRob01d.high <- summary (NobsUNRegRob01d.high <- felm (pbega2 ~ nUN_d45_wequal_any*ele30 | countryYear | 0 | country, data=base)))
(sumNobsUNRegRob01a.low <- summary (NobsUNRegRob01a.low <- felm (pbega2 ~ nUN_d45_wequal_any*wdi_InternetUsers_lag | 0 | 0 | 0, data=base)))
(sumNobsUNRegRob01b.low <- summary (NobsUNRegRob01b.low <- felm (pbega2 ~ nUN_d45_wequal_any*wdi_InternetUsers_lag | countryYear | 0 | 0, data=base)))
(sumNobsUNRegRob01c.low <- summary (NobsUNRegRob01c.low <- felm (pbega2 ~ nUN_d45_wequal_any*wdi_InternetUsers_lag | 0 | 0 | country, data=base)))
(sumNobsUNRegRob01d.low <- summary (NobsUNRegRob01d.low <- felm (pbega2 ~ nUN_d45_wequal_any*wdi_InternetUsers_lag | countryYear | 0 | country, data=base)))

# getting the number of observations
(nobsContRob01.low <- c (length (unique (base[!is.na (base$wdi_InternetUsers_lag),]$country))
                         , length (unique (NobsContRob01d.low$fe$countryYear))
                         , NobsContRob01d.low$N))
(nobsN800Rob01.low <- c (length (unique (base[!is.na (base$wdi_InternetUsers_lag),]$country))
                         , length (unique (NobsN800Rob01d.low$fe$countryYear))
                         , NobsN800Rob01d.low$N))
(nobsUNRegRob01.low <- c (length (unique (base[!is.na (base$wdi_InternetUsers_lag),]$country))
                          , length (unique (NobsUNRegRob01d.low$fe$countryYear))
                          , NobsUNRegRob01d.low$N))
(nobsContRob01.high <- c (length (unique (base[!is.na (base$ele30),]$country))
                          , length (unique (NobsContRob01d.high$fe$countryYear))
                          , NobsContRob01d.high$N))
(nobsN800Rob01.high <- c (length (unique (base[!is.na (base$ele30),]$country))
                          , length (unique (NobsN800Rob01d.high$fe$countryYear))
                          , NobsN800Rob01d.high$N))
(nobsUNRegRob01.high <- c (length (unique (base[!is.na (base$ele30),]$country))
                           , length (unique (NobsUNRegRob01d.high$fe$countryYear))
                           , NobsUNRegRob01d.high$N))

# doing the loop
v <- NULL
mContRob01 <- mN800Rob01 <- mUNRegRob01 <- list ()
mContRob01.vcov <- mN800Rob01.vcov <- mUNRegRob01.vcov <- list ()

system.time (
  for (v in 1:length (vContRob01)){
    
    ## defining the explanatory variable of interest
    base$ivCont <- base[,vContRob01[v]]
    base$ivN800 <- base[,vN800Rob01[v]]
    base$ivUNReg <- base[,vUNRegRob01[v]]
    
    ## (i) Contiguous neighbors
    
    # country-year FEs
    mContRob01[[v+0*length (vContRob01)]] <- summary (felm (pbega2 ~ ivCont*wdi_InternetUsers_lag | countryYear | 0 | country, data=base))$coef
    mContRob01[[v+1*length (vContRob01)]] <- summary (felm (pbega2 ~ ivCont*wdi_GDPcapGrowth_lag | countryYear | 0 | country, data=base))$coef
    mContRob01[[v+2*length (vContRob01)]] <- summary (felm (pbega2 ~ ivCont*physint_lag | countryYear | 0 | country, data=base))$coef
    mContRob01[[v+3*length (vContRob01)]] <- summary (felm (pbega2 ~ ivCont*ele30 | countryYear | 0 | country, data=base))$coef
    mContRob01[[v+4*length (vContRob01)]] <- summary (felm (pbega2 ~ ivCont*wdi_InternetUsers_lag + ele30 | countryYear | 0 | country, data=base))$coef
    mContRob01[[v+5*length (vContRob01)]] <- summary (felm (pbega2 ~ ivCont*wdi_GDPcapGrowth_lag + ele30 | countryYear | 0 | country, data=base))$coef
    mContRob01[[v+6*length (vContRob01)]] <- summary (felm (pbega2 ~ ivCont*physint_lag + ele30 | countryYear | 0 | country, data=base))$coef
    
    # variance/covariance matrices
    mContRob01.vcov[[v+0*length (vContRob01)]] <- vcov (felm (pbega2 ~ ivCont*wdi_InternetUsers_lag | countryYear | 0 | country, data=base))
    mContRob01.vcov[[v+1*length (vContRob01)]] <- vcov (felm (pbega2 ~ ivCont*wdi_GDPcapGrowth_lag | countryYear | 0 | country, data=base))
    mContRob01.vcov[[v+2*length (vContRob01)]] <- vcov (felm (pbega2 ~ ivCont*physint_lag | countryYear | 0 | country, data=base))
    mContRob01.vcov[[v+3*length (vContRob01)]] <- vcov (felm (pbega2 ~ ivCont*ele30 | countryYear | 0 | country, data=base))
    mContRob01.vcov[[v+4*length (vContRob01)]] <- vcov (felm (pbega2 ~ ivCont*wdi_InternetUsers_lag + ele30 | countryYear | 0 | country, data=base))
    mContRob01.vcov[[v+5*length (vContRob01)]] <- vcov (felm (pbega2 ~ ivCont*wdi_GDPcapGrowth_lag + ele30 | countryYear | 0 | country, data=base))
    mContRob01.vcov[[v+6*length (vContRob01)]] <- vcov (felm (pbega2 ~ ivCont*physint_lag + ele30 | countryYear | 0 | country, data=base))
    
    
    ## (ii) 800km neighbors
    
    # country-year FEs
    mN800Rob01[[v+0*length (vN800Rob01)]] <- summary (felm (pbega2 ~ ivN800*wdi_InternetUsers_lag | countryYear | 0 | country, data=base))$coef
    mN800Rob01[[v+1*length (vN800Rob01)]] <- summary (felm (pbega2 ~ ivN800*wdi_GDPcapGrowth_lag | countryYear | 0 | country, data=base))$coef
    mN800Rob01[[v+2*length (vN800Rob01)]] <- summary (felm (pbega2 ~ ivN800*physint_lag | countryYear | 0 | country, data=base))$coef
    mN800Rob01[[v+3*length (vN800Rob01)]] <- summary (felm (pbega2 ~ ivN800*ele30 | countryYear | 0 | country, data=base))$coef
    mN800Rob01[[v+4*length (vN800Rob01)]] <- summary (felm (pbega2 ~ ivN800*wdi_InternetUsers_lag + ele30 | countryYear | 0 | country, data=base))$coef
    mN800Rob01[[v+5*length (vN800Rob01)]] <- summary (felm (pbega2 ~ ivN800*wdi_GDPcapGrowth_lag + ele30 | countryYear | 0 | country, data=base))$coef
    mN800Rob01[[v+6*length (vN800Rob01)]] <- summary (felm (pbega2 ~ ivN800*physint_lag + ele30 | countryYear | 0 | country, data=base))$coef
    
    # variance/covariance matrices
    mN800Rob01.vcov[[v+0*length (vN800Rob01)]] <- vcov (felm (pbega2 ~ ivN800*wdi_InternetUsers_lag | countryYear | 0 | country, data=base))
    mN800Rob01.vcov[[v+1*length (vN800Rob01)]] <- vcov (felm (pbega2 ~ ivN800*wdi_GDPcapGrowth_lag | countryYear | 0 | country, data=base))
    mN800Rob01.vcov[[v+2*length (vN800Rob01)]] <- vcov (felm (pbega2 ~ ivN800*physint_lag | countryYear | 0 | country, data=base))
    mN800Rob01.vcov[[v+3*length (vN800Rob01)]] <- vcov (felm (pbega2 ~ ivN800*ele30 | countryYear | 0 | country, data=base))
    mN800Rob01.vcov[[v+4*length (vN800Rob01)]] <- vcov (felm (pbega2 ~ ivN800*wdi_InternetUsers_lag + ele30 | countryYear | 0 | country, data=base))
    mN800Rob01.vcov[[v+5*length (vN800Rob01)]] <- vcov (felm (pbega2 ~ ivN800*wdi_GDPcapGrowth_lag + ele30 | countryYear | 0 | country, data=base))
    mN800Rob01.vcov[[v+6*length (vN800Rob01)]] <- vcov (felm (pbega2 ~ ivN800*physint_lag + ele30 | countryYear | 0 | country, data=base))
    
    
    ## (iii) UN region neighbors
    
    # country-year FEs
    mUNRegRob01[[v+0*length (vUNRegRob01)]] <- summary (felm (pbega2 ~ ivUNReg*wdi_InternetUsers_lag | countryYear | 0 | country, data=base))$coef
    mUNRegRob01[[v+1*length (vUNRegRob01)]] <- summary (felm (pbega2 ~ ivUNReg*wdi_GDPcapGrowth_lag | countryYear | 0 | country, data=base))$coef
    mUNRegRob01[[v+2*length (vUNRegRob01)]] <- summary (felm (pbega2 ~ ivUNReg*physint_lag | countryYear | 0 | country, data=base))$coef
    mUNRegRob01[[v+3*length (vUNRegRob01)]] <- summary (felm (pbega2 ~ ivUNReg*ele30 | countryYear | 0 | country, data=base))$coef
    mUNRegRob01[[v+4*length (vUNRegRob01)]] <- summary (felm (pbega2 ~ ivUNReg*wdi_InternetUsers_lag + ele30 | countryYear | 0 | country, data=base))$coef
    mUNRegRob01[[v+5*length (vUNRegRob01)]] <- summary (felm (pbega2 ~ ivUNReg*wdi_GDPcapGrowth_lag + ele30 | countryYear | 0 | country, data=base))$coef
    mUNRegRob01[[v+6*length (vUNRegRob01)]] <- summary (felm (pbega2 ~ ivUNReg*physint_lag + ele30 | countryYear | 0 | country, data=base))$coef
    
    # variance/covariance matrices
    mUNRegRob01.vcov[[v+0*length (vUNRegRob01)]] <- vcov (felm (pbega2 ~ ivUNReg*wdi_InternetUsers_lag | countryYear | 0 | country, data=base))
    mUNRegRob01.vcov[[v+1*length (vUNRegRob01)]] <- vcov (felm (pbega2 ~ ivUNReg*wdi_GDPcapGrowth_lag | countryYear | 0 | country, data=base))
    mUNRegRob01.vcov[[v+2*length (vUNRegRob01)]] <- vcov (felm (pbega2 ~ ivUNReg*physint_lag | countryYear | 0 | country, data=base))
    mUNRegRob01.vcov[[v+3*length (vUNRegRob01)]] <- vcov (felm (pbega2 ~ ivUNReg*ele30 | countryYear | 0 | country, data=base))
    mUNRegRob01.vcov[[v+4*length (vUNRegRob01)]] <- vcov (felm (pbega2 ~ ivUNReg*wdi_InternetUsers_lag + ele30 | countryYear | 0 | country, data=base))
    mUNRegRob01.vcov[[v+5*length (vUNRegRob01)]] <- vcov (felm (pbega2 ~ ivUNReg*wdi_GDPcapGrowth_lag + ele30 | countryYear | 0 | country, data=base))
    mUNRegRob01.vcov[[v+6*length (vUNRegRob01)]] <- vcov (felm (pbega2 ~ ivUNReg*physint_lag + ele30 | countryYear | 0 | country, data=base))
  }
) ## 2805 seconds


## (3.2.3) Robustness checks: Alternative specifications

# listing the explanatory variables
vRob09d30 <- c ("n50_d30_wequal_any", "n50_d30_wequal_sum", "n50_d30_wSize_any"
                , "n800_d30_wequal_any", "n800_d30_wequal_sum", "n800_d30_wSize_any"
                , "nUN_d30_wequal_any", "nUN_d30_wequal_sum", "nUN_d30_wSize_any")
vRob09d45 <- c ("n50_d45_wequal_any", "n50_d45_wequal_sum", "n50_d45_wSize_any"
                , "n800_d45_wequal_any", "n800_d45_wequal_sum", "n800_d45_wSize_any"
                , "nUN_d45_wequal_any", "nUN_d45_wequal_sum", "nUN_d45_wSize_any")
vRob09d90 <- c ("n50_d90_wequal_any", "n50_d90_wequal_sum", "n50_d90_wSize_any"
                , "n800_d90_wequal_any", "n800_d90_wequal_sum", "n800_d90_wSize_any"
                , "nUN_d90_wequal_any", "nUN_d90_wequal_sum", "nUN_d90_wSize_any")
vRob09d120 <- c ("n50_d120_wequal_any", "n50_d120_wequal_sum", "n50_d120_wSize_any"
                 , "n800_d120_wequal_any", "n800_d120_wequal_sum", "n800_d120_wSize_any"
                 , "nUN_d120_wequal_any", "nUN_d120_wequal_sum", "nUN_d120_wSize_any")

# running the models
v <- NULL
mRob09d30 <- mRob09d45 <- mRob09d90 <- mRob09d120 <- list () ## we'll put the models here

system.time (
  for (v in 1:length (vRob09d45)){
    
    ## defining the explanatory variable of interest
    base$iv30 <- base[,vRob09d30[v]]
    base$iv45 <- base[,vRob09d45[v]]
    base$iv90 <- base[,vRob09d90[v]]
    base$iv120 <- base[,vRob09d120[v]]
    
    
    ## (i) 30-day time frame
    
    # neither FEs nor clustered SEs
    mRob09d30[[v+0*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 | 0 | 0 | 0, data=base))$coef
    mRob09d30[[v+1*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | 0 | 0 | 0, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY
    mRob09d30[[v+2*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 | 0 | 0 | country, data=base))$coef
    mRob09d30[[v+3*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | 0 | 0 | country, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY-YEAR
    mRob09d30[[v+4*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 | 0 | 0 | countryYear, data=base))$coef
    mRob09d30[[v+5*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | 0 | 0 | countryYear, data=base))$coef
    
    # neither FEs nor clustered SEs + controls
    mRob09d30[[v+6*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | 0, data=base))$coef
    mRob09d30[[v+7*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | 0, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY + controls
    mRob09d30[[v+8*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=base))$coef
    mRob09d30[[v+9*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY-YEAR + controls
    mRob09d30[[v+10*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | countryYear, data=base))$coef
    mRob09d30[[v+11*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | countryYear, data=base))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY
    mRob09d30[[v+12*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 | country | 0 | country, data=base))$coef
    mRob09d30[[v+13*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | country | 0 | country, data=base))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY + Controls
    mRob09d30[[v+14*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=base))$coef
    mRob09d30[[v+15*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=base))$coef
    
    # FEs by COUNTRY and YEAR and SEs clustered by COUNTRY
    mRob09d30[[v+16*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 | country + year | 0 | country, data=base))$coef
    mRob09d30[[v+17*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | country + year | 0 | country, data=base))$coef
    
    # FEs by COUNTRY and YEAR and SEs clustered by COUNTRY + Controls
    mRob09d30[[v+18*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country + year | 0 | country, data=base))$coef
    mRob09d30[[v+19*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country + year | 0 | country, data=base))$coef
    
    # FEs by COUNTRY-DECADE and SEs clustered by COUNTRY
    mRob09d30[[v+20*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 | cdecade | 0 | country, data=base))$coef
    mRob09d30[[v+21*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | cdecade | 0 | country, data=base))$coef
    
    # FEs by COUNTRY-DECADE and SEs clustered by COUNTRY + Controls
    mRob09d30[[v+22*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | cdecade | 0 | country, data=base))$coef
    mRob09d30[[v+23*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | cdecade | 0 | country, data=base))$coef
    
    # FEs by REGION-YEAR and SEs clustered by COUNTRY
    mRob09d30[[v+24*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 | ryear | 0 | country, data=base))$coef
    mRob09d30[[v+25*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | ryear | 0 | country, data=base))$coef
    
    # FEs by REGION-YEAR and SEs clustered by COUNTRY + Controls
    mRob09d30[[v+26*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | ryear | 0 | country, data=base))$coef
    mRob09d30[[v+27*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | ryear | 0 | country, data=base))$coef
    
    # FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob09d30[[v+28*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 | countryYear | 0 | country, data=base))$coef
    mRob09d30[[v+29*length (vRob09d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | countryYear | 0 | country, data=base))$coef
    
    # REs by COUNTRY, standard SEs
    mRob09d30[[v+30*length (vRob09d30)]] <- summary (glmer (pbega ~ iv30 + (1|country), family=binomial(link="logit"), data=base))$coef
    mRob09d30[[v+31*length (vRob09d30)]] <- summary (glmer (pbega ~ iv30 + ele30 + (1|country), family=binomial(link="logit"), data=base))$coef
    
    # REs by COUNTRY-YEAR, standars SEs
    mRob09d30[[v+32*length (vRob09d30)]] <- summary (glmer (pbega ~ iv30 + (1|countryYear), family=binomial(link="logit"), data=base))$coef
    mRob09d30[[v+33*length (vRob09d30)]] <- summary (glmer (pbega ~ iv30 + ele30 + (1|countryYear), family=binomial(link="logit"), data=base))$coef
    
    
    ## (ii) 45-day time frame
    
    # neither FEs nor clustered SEs
    mRob09d45[[v+0*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 | 0 | 0 | 0, data=base))$coef
    mRob09d45[[v+1*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | 0 | 0 | 0, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY
    mRob09d45[[v+2*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 | 0 | 0 | country, data=base))$coef
    mRob09d45[[v+3*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | 0 | 0 | country, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY-YEAR
    mRob09d45[[v+4*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 | 0 | 0 | countryYear, data=base))$coef
    mRob09d45[[v+5*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | 0 | 0 | countryYear, data=base))$coef
    
    # neither FEs nor clustered SEs + controls
    mRob09d45[[v+6*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | 0, data=base))$coef
    mRob09d45[[v+7*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | 0, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY + controls
    mRob09d45[[v+8*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=base))$coef
    mRob09d45[[v+9*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY-YEAR + controls
    mRob09d45[[v+10*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | countryYear, data=base))$coef
    mRob09d45[[v+11*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | countryYear, data=base))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY
    mRob09d45[[v+12*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 | country | 0 | country, data=base))$coef
    mRob09d45[[v+13*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | country | 0 | country, data=base))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY + Controls
    mRob09d45[[v+14*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=base))$coef
    mRob09d45[[v+15*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=base))$coef
    
    # FEs by COUNTRY and YEAR and SEs clustered by COUNTRY
    mRob09d45[[v+16*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 | country + year | 0 | country, data=base))$coef
    mRob09d45[[v+17*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | country + year | 0 | country, data=base))$coef
    
    # FEs by COUNTRY and YEAR and SEs clustered by COUNTRY + Controls
    mRob09d45[[v+18*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country + year | 0 | country, data=base))$coef
    mRob09d45[[v+19*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country + year | 0 | country, data=base))$coef
    
    # FEs by COUNTRY-DECADE and SEs clustered by COUNTRY
    mRob09d45[[v+20*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 | cdecade | 0 | country, data=base))$coef
    mRob09d45[[v+21*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | cdecade | 0 | country, data=base))$coef
    
    # FEs by COUNTRY-DECADE and SEs clustered by COUNTRY + Controls
    mRob09d45[[v+22*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | cdecade | 0 | country, data=base))$coef
    mRob09d45[[v+23*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | cdecade | 0 | country, data=base))$coef
    
    # FEs by REGION-YEAR and SEs clustered by COUNTRY
    mRob09d45[[v+24*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 | ryear | 0 | country, data=base))$coef
    mRob09d45[[v+25*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | ryear | 0 | country, data=base))$coef
    
    # FEs by REGION-YEAR and SEs clustered by COUNTRY + Controls
    mRob09d45[[v+26*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | ryear | 0 | country, data=base))$coef
    mRob09d45[[v+27*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | ryear | 0 | country, data=base))$coef
    
    # FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob09d45[[v+28*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 | countryYear | 0 | country, data=base))$coef
    mRob09d45[[v+29*length (vRob09d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | countryYear | 0 | country, data=base))$coef
    
    # REs by COUNTRY, standard SEs
    mRob09d45[[v+30*length (vRob09d45)]] <- summary (glmer (pbega ~ iv45 + (1|country), family=binomial(link="logit"), data=base))$coef
    mRob09d45[[v+31*length (vRob09d45)]] <- summary (glmer (pbega ~ iv45 + ele45 + (1|country), family=binomial(link="logit"), data=base))$coef
    
    # REs by COUNTRY-YEAR, standars SEs
    mRob09d45[[v+32*length (vRob09d45)]] <- summary (glmer (pbega ~ iv45 + (1|countryYear), family=binomial(link="logit"), data=base))$coef
    mRob09d45[[v+33*length (vRob09d45)]] <- summary (glmer (pbega ~ iv45 + ele45 + (1|countryYear), family=binomial(link="logit"), data=base))$coef
    
    
    ## (iii) 90-day time frame
    
    # neither FEs nor clustered SEs
    mRob09d90[[v+0*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 | 0 | 0 | 0, data=base))$coef
    mRob09d90[[v+1*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | 0 | 0 | 0, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY
    mRob09d90[[v+2*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 | 0 | 0 | country, data=base))$coef
    mRob09d90[[v+3*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | 0 | 0 | country, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY-YEAR
    mRob09d90[[v+4*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 | 0 | 0 | countryYear, data=base))$coef
    mRob09d90[[v+5*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | 0 | 0 | countryYear, data=base))$coef
    
    # neither FEs nor clustered SEs + controls
    mRob09d90[[v+6*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | 0, data=base))$coef
    mRob09d90[[v+7*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | 0, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY + controls
    mRob09d90[[v+8*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=base))$coef
    mRob09d90[[v+9*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY-YEAR + controls
    mRob09d90[[v+10*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | countryYear, data=base))$coef
    mRob09d90[[v+11*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | countryYear, data=base))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY
    mRob09d90[[v+12*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 | country | 0 | country, data=base))$coef
    mRob09d90[[v+13*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | country | 0 | country, data=base))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY + Controls
    mRob09d90[[v+14*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=base))$coef
    mRob09d90[[v+15*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=base))$coef
    
    # FEs by COUNTRY and YEAR and SEs clustered by COUNTRY
    mRob09d90[[v+16*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 | country + year | 0 | country, data=base))$coef
    mRob09d90[[v+17*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | country + year | 0 | country, data=base))$coef
    
    # FEs by COUNTRY and YEAR and SEs clustered by COUNTRY + Controls
    mRob09d90[[v+18*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country + year | 0 | country, data=base))$coef
    mRob09d90[[v+19*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country + year | 0 | country, data=base))$coef
    
    # FEs by COUNTRY-DECADE and SEs clustered by COUNTRY
    mRob09d90[[v+20*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 | cdecade | 0 | country, data=base))$coef
    mRob09d90[[v+21*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | cdecade | 0 | country, data=base))$coef
    
    # FEs by COUNTRY-DECADE and SEs clustered by COUNTRY + Controls
    mRob09d90[[v+22*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | cdecade | 0 | country, data=base))$coef
    mRob09d90[[v+23*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | cdecade | 0 | country, data=base))$coef
    
    # FEs by REGION-YEAR and SEs clustered by COUNTRY
    mRob09d90[[v+24*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 | ryear | 0 | country, data=base))$coef
    mRob09d90[[v+25*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | ryear | 0 | country, data=base))$coef
    
    # FEs by REGION-YEAR and SEs clustered by COUNTRY + Controls
    mRob09d90[[v+26*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | ryear | 0 | country, data=base))$coef
    mRob09d90[[v+27*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | ryear | 0 | country, data=base))$coef
    
    # FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob09d90[[v+28*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 | countryYear | 0 | country, data=base))$coef
    mRob09d90[[v+29*length (vRob09d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | countryYear | 0 | country, data=base))$coef
    
    # REs by COUNTRY, standard SEs
    mRob09d90[[v+30*length (vRob09d90)]] <- summary (glmer (pbega ~ iv90 + (1|country), family=binomial(link="logit"), data=base))$coef
    mRob09d90[[v+31*length (vRob09d90)]] <- summary (glmer (pbega ~ iv90 + ele90 + (1|country), family=binomial(link="logit"), data=base))$coef
    
    # REs by COUNTRY-YEAR, standars SEs
    mRob09d90[[v+32*length (vRob09d90)]] <- summary (glmer (pbega ~ iv90 + (1|countryYear), family=binomial(link="logit"), data=base))$coef
    mRob09d90[[v+33*length (vRob09d90)]] <- summary (glmer (pbega ~ iv90 + ele90 + (1|countryYear), family=binomial(link="logit"), data=base))$coef
    
    
    ## (iv) 120-day time frame
    
    # neither FEs nor clustered SEs
    mRob09d120[[v+0*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 | 0 | 0 | 0, data=base))$coef
    mRob09d120[[v+1*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | 0 | 0 | 0, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY
    mRob09d120[[v+2*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 | 0 | 0 | country, data=base))$coef
    mRob09d120[[v+3*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | 0 | 0 | country, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY-YEAR
    mRob09d120[[v+4*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 | 0 | 0 | countryYear, data=base))$coef
    mRob09d120[[v+5*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | 0 | 0 | countryYear, data=base))$coef
    
    # neither FEs nor clustered SEs + controls
    mRob09d120[[v+6*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | 0, data=base))$coef
    mRob09d120[[v+7*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | 0, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY + controls
    mRob09d120[[v+8*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=base))$coef
    mRob09d120[[v+9*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=base))$coef
    
    # no FEs but SEs clustered by COUNTRY-YEAR + controls
    mRob09d120[[v+10*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | countryYear, data=base))$coef
    mRob09d120[[v+11*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | countryYear, data=base))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY
    mRob09d120[[v+12*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 | country | 0 | country, data=base))$coef
    mRob09d120[[v+13*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | country | 0 | country, data=base))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY + Controls
    mRob09d120[[v+14*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=base))$coef
    mRob09d120[[v+15*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=base))$coef
    
    # FEs by COUNTRY and YEAR and SEs clustered by COUNTRY
    mRob09d120[[v+16*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 | country + year | 0 | country, data=base))$coef
    mRob09d120[[v+17*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | country + year | 0 | country, data=base))$coef
    
    # FEs by COUNTRY and YEAR and SEs clustered by COUNTRY + Controls
    mRob09d120[[v+18*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country + year | 0 | country, data=base))$coef
    mRob09d120[[v+19*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country + year | 0 | country, data=base))$coef
    
    # FEs by COUNTRY-DECADE and SEs clustered by COUNTRY
    mRob09d120[[v+20*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 | cdecade | 0 | country, data=base))$coef
    mRob09d120[[v+21*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | cdecade | 0 | country, data=base))$coef
    
    # FEs by COUNTRY-DECADE and SEs clustered by COUNTRY + Controls
    mRob09d120[[v+22*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | cdecade | 0 | country, data=base))$coef
    mRob09d120[[v+23*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | cdecade | 0 | country, data=base))$coef
    
    # FEs by REGION-YEAR and SEs clustered by COUNTRY
    mRob09d120[[v+24*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 | ryear | 0 | country, data=base))$coef
    mRob09d120[[v+25*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | ryear | 0 | country, data=base))$coef
    
    # FEs by REGION-YEAR and SEs clustered by COUNTRY + Controls
    mRob09d120[[v+26*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | ryear | 0 | country, data=base))$coef
    mRob09d120[[v+27*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | ryear | 0 | country, data=base))$coef
    
    # FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob09d120[[v+28*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 | countryYear | 0 | country, data=base))$coef
    mRob09d120[[v+29*length (vRob09d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | countryYear | 0 | country, data=base))$coef
    
    # REs by COUNTRY, standard SEs
    mRob09d120[[v+30*length (vRob09d120)]] <- summary (glmer (pbega ~ iv120 + (1|country), family=binomial(link="logit"), data=base))$coef
    mRob09d120[[v+31*length (vRob09d120)]] <- summary (glmer (pbega ~ iv120 + ele120 + (1|country), family=binomial(link="logit"), data=base))$coef
    
    # REs by COUNTRY-YEAR, standars SEs
    mRob09d120[[v+32*length (vRob09d120)]] <- summary (glmer (pbega ~ iv120 + (1|countryYear), family=binomial(link="logit"), data=base))$coef
    mRob09d120[[v+33*length (vRob09d120)]] <- summary (glmer (pbega ~ iv120 + ele120 + (1|countryYear), family=binomial(link="logit"), data=base))$coef
  }
) ## 99863 seconds (1664 minutes, 27.7 hours)


## (3.2.4) Robustness checks: Weekly data

# listing the explanatory variables
vRob10w04 <- c ("n50_d30_wequal_any", "n50_d30_wequal_sum", "n50_d30_wSize_any"
                , "n800_d30_wequal_any", "n800_d30_wequal_sum", "n800_d30_wSize_any"
                , "nUN_d30_wequal_any", "nUN_d30_wequal_sum", "nUN_d30_wSize_any")
vRob10w06 <- c ("n50_d45_wequal_any", "n50_d45_wequal_sum", "n50_d45_wSize_any"
                , "n800_d45_wequal_any", "n800_d45_wequal_sum", "n800_d45_wSize_any"
                , "nUN_d45_wequal_any", "nUN_d45_wequal_sum", "nUN_d45_wSize_any")
vRob10w12 <- c ("n50_d90_wequal_any", "n50_d90_wequal_sum", "n50_d90_wSize_any"
                , "n800_d90_wequal_any", "n800_d90_wequal_sum", "n800_d90_wSize_any"
                , "nUN_d90_wequal_any", "nUN_d90_wequal_sum", "nUN_d90_wSize_any")
vRob10w18 <- c ("n50_d120_wequal_any", "n50_d120_wequal_sum", "n50_d120_wSize_any"
                , "n800_d120_wequal_any", "n800_d120_wequal_sum", "n800_d120_wSize_any"
                , "nUN_d120_wequal_any", "nUN_d120_wequal_sum", "nUN_d120_wSize_any")

## running one model to get the number of observations
(sumNweeksCont01a <- summary (NweeksCont01a <- felm (pbega2 ~ n50_d45_wequal_any | 0 | 0 | 0, data=bweek)))
(sumNweeksCont01b <- summary (NweeksCont01b <- felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | 0, data=bweek)))
(sumNweeksCont01c <- summary (NweeksCont01c <- felm (pbega2 ~ n50_d45_wequal_any | 0 | 0 | country, data=bweek)))
(sumNweeksCont01d <- summary (NweeksCont01d <- felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=bweek)))
(sumNweeksCont01e <- summary (NweeksCont01e <- felm (pbega2 ~ n50_d45_wequal_any + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bweek)))

(sumNweeksN80001a <- summary (NweeksN80001a <- felm (pbega2 ~ n800_d45_wequal_any | 0 | 0 | 0, data=bweek)))
(sumNweeksN80001b <- summary (NweeksN80001b <- felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | 0, data=bweek)))
(sumNweeksN80001c <- summary (NweeksN80001c <- felm (pbega2 ~ n800_d45_wequal_any | 0 | 0 | country, data=bweek)))
(sumNweeksN80001d <- summary (NweeksN80001d <- felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=bweek)))
(sumNweeksN80001e <- summary (NweeksN80001e <- felm (pbega2 ~ n800_d45_wequal_any + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bweek)))

(sumNweeksUNReg01a <- summary (NweeksUNReg01a <- felm (pbega2 ~ nUN_d45_wequal_any | 0 | 0 | 0, data=bweek)))
(sumNweeksUNReg01b <- summary (NweeksUNReg01b <- felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | 0, data=bweek)))
(sumNweeksUNReg01c <- summary (NweeksUNReg01c <- felm (pbega2 ~ nUN_d45_wequal_any | 0 | 0 | country, data=bweek)))
(sumNweeksUNReg01d <- summary (NweeksUNReg01d <- felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=bweek)))
(sumNweeksUNReg01e <- summary (NweeksUNReg01e <- felm (pbega2 ~ nUN_d45_wequal_any + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bweek)))

# getting the number of observations
(nweeksCont01main <- c (length (unique (bweek[!is.na (bweek$n50_d45_wequal_any),]$country))
                        , length (unique (NweeksCont01d$fe$countryYear))
                        , NweeksCont01d$N))
(nweeksN80001main <- c (length (unique (bweek[!is.na (bweek$n800_d45_wequal_any),]$country))
                        , length (unique (NweeksN80001d$fe$countryYear))
                        , NweeksN80001d$N))
(nweeksUNReg01main <- c (length (unique (bweek[!is.na (bweek$nUN_d45_wequal_any),]$country))
                         , length (unique (NweeksUNReg01d$fe$countryYear))
                         , NweeksUNReg01d$N))
(nweeksCont01controls <- c (length (unique (bweek[!is.na (bweek$n50_d45_wequal_any) & !is.na (bweek$wdi_GDPcap_lag) & !is.na (bweek$wdi_GDPcap_lag) & !is.na (bweek$wdi_GDPcapGrowth_lag) & !is.na (bweek$pop_lag) & !is.na (bweek$physint_lag) & !is.na (bweek$polity),]$country))
                            , length (unique (bweek[!is.na (bweek$n50_d45_wequal_any) & !is.na (bweek$wdi_GDPcap_lag) & !is.na (bweek$wdi_GDPcap_lag) & !is.na (bweek$wdi_GDPcapGrowth_lag) & !is.na (bweek$pop_lag) & !is.na (bweek$physint_lag) & !is.na (bweek$polity),]$countryYear))
                            , NweeksCont01e$N))
(nweeksN80001controls <- c (length (unique (bweek[!is.na (bweek$n800_d45_wequal_any) & !is.na (bweek$wdi_GDPcap_lag) & !is.na (bweek$wdi_GDPcap_lag) & !is.na (bweek$wdi_GDPcapGrowth_lag) & !is.na (bweek$pop_lag) & !is.na (bweek$physint_lag) & !is.na (bweek$polity),]$country))
                            , length (unique (bweek[!is.na (bweek$n800_d45_wequal_any) & !is.na (bweek$wdi_GDPcap_lag) & !is.na (bweek$wdi_GDPcap_lag) & !is.na (bweek$wdi_GDPcapGrowth_lag) & !is.na (bweek$pop_lag) & !is.na (bweek$physint_lag) & !is.na (bweek$polity),]$countryYear))
                            , NweeksN80001e$N))
(nweeksUNReg01controls <- c (length (unique (bweek[!is.na (bweek$nUN_d45_wequal_any) & !is.na (bweek$wdi_GDPcap_lag) & !is.na (bweek$wdi_GDPcap_lag) & !is.na (bweek$wdi_GDPcapGrowth_lag) & !is.na (bweek$pop_lag) & !is.na (bweek$physint_lag) & !is.na (bweek$polity),]$country))
                             , length (unique (bweek[!is.na (bweek$nUN_d45_wequal_any) & !is.na (bweek$wdi_GDPcap_lag) & !is.na (bweek$wdi_GDPcap_lag) & !is.na (bweek$wdi_GDPcapGrowth_lag) & !is.na (bweek$pop_lag) & !is.na (bweek$physint_lag) & !is.na (bweek$polity),]$countryYear))
                             , NweeksUNReg01e$N))

# running the models
v <- NULL
mRob10w04 <- mRob10w06 <- mRob10w12 <- mRob10w18 <- list () ## we'll put the models here

system.time (
  for (v in 1:length (vRob10w06)){
    
    ## defining the explanatory variable of interest
    bweek$iv04 <- bweek[,vRob10w04[v]]
    bweek$iv06 <- bweek[,vRob10w06[v]]
    bweek$iv12 <- bweek[,vRob10w12[v]]
    bweek$iv18 <- bweek[,vRob10w18[v]]
    
    
    ## (i) 4-week time frame
    
    # neither FEs nor clustered SEs
    mRob10w04[[v+0*length (vRob10w04)]] <- summary (felm (pbega2 ~ iv04 | 0 | 0 | 0, data=bweek))$coef
    mRob10w04[[v+1*length (vRob10w04)]] <- summary (felm (pbega2 ~ iv04 + ele04b | 0 | 0 | 0, data=bweek))$coef
    
    # no FEs but SEs clustered by COUNTRY
    mRob10w04[[v+2*length (vRob10w04)]] <- summary (felm (pbega2 ~ iv04 | 0 | 0 | country, data=bweek))$coef
    mRob10w04[[v+3*length (vRob10w04)]] <- summary (felm (pbega2 ~ iv04 + ele04b | 0 | 0 | country, data=bweek))$coef
    
    # no FEs but SEs clustered by COUNTRY + controls
    mRob10w04[[v+4*length (vRob10w04)]] <- summary (felm (pbega2 ~ iv04 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bweek))$coef
    mRob10w04[[v+5*length (vRob10w04)]] <- summary (felm (pbega2 ~ iv04 + ele04b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bweek))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY
    mRob10w04[[v+6*length (vRob10w04)]] <- summary (felm (pbega2 ~ iv04 | country | 0 | country, data=bweek))$coef
    mRob10w04[[v+7*length (vRob10w04)]] <- summary (felm (pbega2 ~ iv04 + ele04b | country | 0 | country, data=bweek))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY + Controls
    mRob10w04[[v+8*length (vRob10w04)]] <- summary (felm (pbega2 ~ iv04 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bweek))$coef
    mRob10w04[[v+9*length (vRob10w04)]] <- summary (felm (pbega2 ~ iv04 + ele04b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bweek))$coef
    
    # FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob10w04[[v+10*length (vRob10w04)]] <- summary (felm (pbega2 ~ iv04 | countryYear | 0 | country, data=bweek))$coef
    mRob10w04[[v+11*length (vRob10w04)]] <- summary (felm (pbega2 ~ iv04 + ele04b | countryYear | 0 | country, data=bweek))$coef
    
    # REs by COUNTRY, standard SEs
    mRob10w04[[v+12*length (vRob10w04)]] <- summary (glmer (pbega ~ iv04 + (1|country), family=binomial(link="logit"), data=bweek))$coef
    mRob10w04[[v+13*length (vRob10w04)]] <- summary (glmer (pbega ~ iv04 + ele04b + (1|country), family=binomial(link="logit"), data=bweek))$coef
    
    # REs by COUNTRY-YEAR, standars SEs
    mRob10w04[[v+14*length (vRob10w04)]] <- summary (glmer (pbega ~ iv04 + (1|countryYear), family=binomial(link="logit"), data=bweek))$coef
    mRob10w04[[v+15*length (vRob10w04)]] <- summary (glmer (pbega ~ iv04 + ele04b + (1|countryYear), family=binomial(link="logit"), data=bweek))$coef
    
    
    ## (ii) 6-week time frame
    
    # neither FEs nor clustered SEs
    mRob10w06[[v+0*length (vRob10w06)]] <- summary (felm (pbega2 ~ iv06 | 0 | 0 | 0, data=bweek))$coef
    mRob10w06[[v+1*length (vRob10w06)]] <- summary (felm (pbega2 ~ iv06 + ele06b | 0 | 0 | 0, data=bweek))$coef
    
    # no FEs but SEs clustered by COUNTRY
    mRob10w06[[v+2*length (vRob10w06)]] <- summary (felm (pbega2 ~ iv06 | 0 | 0 | country, data=bweek))$coef
    mRob10w06[[v+3*length (vRob10w06)]] <- summary (felm (pbega2 ~ iv06 + ele06b | 0 | 0 | country, data=bweek))$coef
    
    # no FEs but SEs clustered by COUNTRY + controls
    mRob10w06[[v+4*length (vRob10w06)]] <- summary (felm (pbega2 ~ iv06 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bweek))$coef
    mRob10w06[[v+5*length (vRob10w06)]] <- summary (felm (pbega2 ~ iv06 + ele06b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bweek))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY
    mRob10w06[[v+6*length (vRob10w06)]] <- summary (felm (pbega2 ~ iv06 | country | 0 | country, data=bweek))$coef
    mRob10w06[[v+7*length (vRob10w06)]] <- summary (felm (pbega2 ~ iv06 + ele06b | country | 0 | country, data=bweek))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY + Controls
    mRob10w06[[v+8*length (vRob10w06)]] <- summary (felm (pbega2 ~ iv06 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bweek))$coef
    mRob10w06[[v+9*length (vRob10w06)]] <- summary (felm (pbega2 ~ iv06 + ele06b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bweek))$coef
    
    # FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob10w06[[v+10*length (vRob10w06)]] <- summary (felm (pbega2 ~ iv06 | countryYear | 0 | country, data=bweek))$coef
    mRob10w06[[v+11*length (vRob10w06)]] <- summary (felm (pbega2 ~ iv06 + ele06b | countryYear | 0 | country, data=bweek))$coef
    
    # REs by COUNTRY, standard SEs
    mRob10w06[[v+12*length (vRob10w06)]] <- summary (glmer (pbega ~ iv06 + (1|country), family=binomial(link="logit"), data=bweek))$coef
    mRob10w06[[v+13*length (vRob10w06)]] <- summary (glmer (pbega ~ iv06 + ele06b + (1|country), family=binomial(link="logit"), data=bweek))$coef
    
    # REs by COUNTRY-YEAR, standars SEs
    mRob10w06[[v+14*length (vRob10w06)]] <- summary (glmer (pbega ~ iv06 + (1|countryYear), family=binomial(link="logit"), data=bweek))$coef
    mRob10w06[[v+15*length (vRob10w06)]] <- summary (glmer (pbega ~ iv06 + ele06b + (1|countryYear), family=binomial(link="logit"), data=bweek))$coef
    
    
    ## (iii) 12-week time frame
    
    # neither FEs nor clustered SEs
    mRob10w12[[v+0*length (vRob10w12)]] <- summary (felm (pbega2 ~ iv12 | 0 | 0 | 0, data=bweek))$coef
    mRob10w12[[v+1*length (vRob10w12)]] <- summary (felm (pbega2 ~ iv12 + ele12b | 0 | 0 | 0, data=bweek))$coef
    
    # no FEs but SEs clustered by COUNTRY
    mRob10w12[[v+2*length (vRob10w12)]] <- summary (felm (pbega2 ~ iv12 | 0 | 0 | country, data=bweek))$coef
    mRob10w12[[v+3*length (vRob10w12)]] <- summary (felm (pbega2 ~ iv12 + ele12b | 0 | 0 | country, data=bweek))$coef
    
    # no FEs but SEs clustered by COUNTRY + controls
    mRob10w12[[v+4*length (vRob10w12)]] <- summary (felm (pbega2 ~ iv12 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bweek))$coef
    mRob10w12[[v+5*length (vRob10w12)]] <- summary (felm (pbega2 ~ iv12 + ele12b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bweek))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY
    mRob10w12[[v+6*length (vRob10w12)]] <- summary (felm (pbega2 ~ iv12 | country | 0 | country, data=bweek))$coef
    mRob10w12[[v+7*length (vRob10w12)]] <- summary (felm (pbega2 ~ iv12 + ele12b | country | 0 | country, data=bweek))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY + Controls
    mRob10w12[[v+8*length (vRob10w12)]] <- summary (felm (pbega2 ~ iv12 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bweek))$coef
    mRob10w12[[v+9*length (vRob10w12)]] <- summary (felm (pbega2 ~ iv12 + ele12b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bweek))$coef
    
    # FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob10w12[[v+10*length (vRob10w12)]] <- summary (felm (pbega2 ~ iv12 | countryYear | 0 | country, data=bweek))$coef
    mRob10w12[[v+11*length (vRob10w12)]] <- summary (felm (pbega2 ~ iv12 + ele12b | countryYear | 0 | country, data=bweek))$coef
    
    # REs by COUNTRY, standard SEs
    mRob10w12[[v+12*length (vRob10w12)]] <- summary (glmer (pbega ~ iv12 + (1|country), family=binomial(link="logit"), data=bweek))$coef
    mRob10w12[[v+13*length (vRob10w12)]] <- summary (glmer (pbega ~ iv12 + ele12b + (1|country), family=binomial(link="logit"), data=bweek))$coef
    
    # REs by COUNTRY-YEAR, standars SEs
    mRob10w12[[v+14*length (vRob10w12)]] <- summary (glmer (pbega ~ iv12 + (1|countryYear), family=binomial(link="logit"), data=bweek))$coef
    mRob10w12[[v+15*length (vRob10w12)]] <- summary (glmer (pbega ~ iv12 + ele12b + (1|countryYear), family=binomial(link="logit"), data=bweek))$coef
    
    
    ## (iv) 18-week time frame
    
    # neither FEs nor clustered SEs
    mRob10w18[[v+0*length (vRob10w18)]] <- summary (felm (pbega2 ~ iv18 | 0 | 0 | 0, data=bweek))$coef
    mRob10w18[[v+1*length (vRob10w18)]] <- summary (felm (pbega2 ~ iv18 + ele18b | 0 | 0 | 0, data=bweek))$coef
    
    # no FEs but SEs clustered by COUNTRY
    mRob10w18[[v+2*length (vRob10w18)]] <- summary (felm (pbega2 ~ iv18 | 0 | 0 | country, data=bweek))$coef
    mRob10w18[[v+3*length (vRob10w18)]] <- summary (felm (pbega2 ~ iv18 + ele18b | 0 | 0 | country, data=bweek))$coef
    
    # no FEs but SEs clustered by COUNTRY + controls
    mRob10w18[[v+4*length (vRob10w18)]] <- summary (felm (pbega2 ~ iv18 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bweek))$coef
    mRob10w18[[v+5*length (vRob10w18)]] <- summary (felm (pbega2 ~ iv18 + ele18b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bweek))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY
    mRob10w18[[v+6*length (vRob10w18)]] <- summary (felm (pbega2 ~ iv18 | country | 0 | country, data=bweek))$coef
    mRob10w18[[v+7*length (vRob10w18)]] <- summary (felm (pbega2 ~ iv18 + ele18b | country | 0 | country, data=bweek))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY + Controls
    mRob10w18[[v+8*length (vRob10w18)]] <- summary (felm (pbega2 ~ iv18 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bweek))$coef
    mRob10w18[[v+9*length (vRob10w18)]] <- summary (felm (pbega2 ~ iv18 + ele18b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bweek))$coef
    
    # FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob10w18[[v+10*length (vRob10w18)]] <- summary (felm (pbega2 ~ iv18 | countryYear | 0 | country, data=bweek))$coef
    mRob10w18[[v+11*length (vRob10w18)]] <- summary (felm (pbega2 ~ iv18 + ele18b | countryYear | 0 | country, data=bweek))$coef
    
    # REs by COUNTRY, standard SEs
    mRob10w18[[v+12*length (vRob10w18)]] <- summary (glmer (pbega ~ iv18 + (1|country), family=binomial(link="logit"), data=bweek))$coef
    mRob10w18[[v+13*length (vRob10w18)]] <- summary (glmer (pbega ~ iv18 + ele18b + (1|country), family=binomial(link="logit"), data=bweek))$coef
    
    # REs by COUNTRY-YEAR, standars SEs
    mRob10w18[[v+14*length (vRob10w18)]] <- summary (glmer (pbega ~ iv18 + (1|countryYear), family=binomial(link="logit"), data=bweek))$coef
    mRob10w18[[v+15*length (vRob10w18)]] <- summary (glmer (pbega ~ iv18 + ele18b + (1|countryYear), family=binomial(link="logit"), data=bweek))$coef
  }
) ## 17683 seconds


## (3.2.5) Robustness checks: Monthly data

# listing the explanatory variables
vRob11m01 <- c ("n50_d30_wequal_any", "n50_d30_wequal_sum", "n50_d30_wSize_any"
                , "n800_d30_wequal_any", "n800_d30_wequal_sum", "n800_d30_wSize_any"
                , "nUN_d30_wequal_any", "nUN_d30_wequal_sum", "nUN_d30_wSize_any")
vRob11m02 <- c ("n50_d45_wequal_any", "n50_d45_wequal_sum", "n50_d45_wSize_any"
                , "n800_d45_wequal_any", "n800_d45_wequal_sum", "n800_d45_wSize_any"
                , "nUN_d45_wequal_any", "nUN_d45_wequal_sum", "nUN_d45_wSize_any")
vRob11m03 <- c ("n50_d90_wequal_any", "n50_d90_wequal_sum", "n50_d90_wSize_any"
                , "n800_d90_wequal_any", "n800_d90_wequal_sum", "n800_d90_wSize_any"
                , "nUN_d90_wequal_any", "nUN_d90_wequal_sum", "nUN_d90_wSize_any")
vRob11m04 <- c ("n50_d120_wequal_any", "n50_d120_wequal_sum", "n50_d120_wSize_any"
                , "n800_d120_wequal_any", "n800_d120_wequal_sum", "n800_d120_wSize_any"
                , "nUN_d120_wequal_any", "nUN_d120_wequal_sum", "nUN_d120_wSize_any")

# running one model to get the number of observations
(sumNmonthsCont01a <- summary (NmonthsCont01a <- felm (pbega2 ~ n50_d45_wequal_any | 0 | 0 | 0, data=bmonth)))
(sumNmonthsCont01b <- summary (NmonthsCont01b <- felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | 0, data=bmonth)))
(sumNmonthsCont01c <- summary (NmonthsCont01c <- felm (pbega2 ~ n50_d45_wequal_any | 0 | 0 | country, data=bmonth)))
(sumNmonthsCont01d <- summary (NmonthsCont01d <- felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=bmonth)))
(sumNmonthsCont01e <- summary (NmonthsCont01e <- felm (pbega2 ~ n50_d45_wequal_any + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bmonth)))

(sumNmonthsN80001a <- summary (NmonthsN80001a <- felm (pbega2 ~ n800_d45_wequal_any | 0 | 0 | 0, data=bmonth)))
(sumNmonthsN80001b <- summary (NmonthsN80001b <- felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | 0, data=bmonth)))
(sumNmonthsN80001c <- summary (NmonthsN80001c <- felm (pbega2 ~ n800_d45_wequal_any | 0 | 0 | country, data=bmonth)))
(sumNmonthsN80001d <- summary (NmonthsN80001d <- felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=bmonth)))
(sumNmonthsN80001e <- summary (NmonthsN80001e <- felm (pbega2 ~ n800_d45_wequal_any + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bmonth)))

(sumNmonthsUNReg01a <- summary (NmonthsUNReg01a <- felm (pbega2 ~ nUN_d45_wequal_any | 0 | 0 | 0, data=bmonth)))
(sumNmonthsUNReg01b <- summary (NmonthsUNReg01b <- felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | 0, data=bmonth)))
(sumNmonthsUNReg01c <- summary (NmonthsUNReg01c <- felm (pbega2 ~ nUN_d45_wequal_any | 0 | 0 | country, data=bmonth)))
(sumNmonthsUNReg01d <- summary (NmonthsUNReg01d <- felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=bmonth)))
(sumNmonthsUNReg01e <- summary (NmonthsUNReg01e <- felm (pbega2 ~ nUN_d45_wequal_any + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bmonth)))

# getting the number of observations
(nmonthsCont01main <- c (length (unique (bmonth[!is.na (bmonth$n50_d45_wequal_any),]$country))
                         , length (unique (NmonthsCont01d$fe$countryYear))
                         , NmonthsCont01d$N))
(nmonthsN80001main <- c (length (unique (bmonth[!is.na (bmonth$n800_d45_wequal_any),]$country))
                         , length (unique (NmonthsN80001d$fe$countryYear))
                         , NmonthsN80001d$N))
(nmonthsUNReg01main <- c (length (unique (bmonth[!is.na (bmonth$nUN_d45_wequal_any),]$country))
                          , length (unique (NmonthsUNReg01d$fe$countryYear))
                          , NmonthsUNReg01d$N))

(nmonthsCont01controls <- c (length (unique (bmonth[!is.na (bmonth$n50_d45_wequal_any) & !is.na (bmonth$wdi_GDPcap_lag) & !is.na (bmonth$wdi_GDPcap_lag) & !is.na (bmonth$wdi_GDPcapGrowth_lag) & !is.na (bmonth$pop_lag) & !is.na (bmonth$physint_lag) & !is.na (bmonth$polity),]$country))
                             , length (unique (bmonth[!is.na (bmonth$n50_d45_wequal_any) & !is.na (bmonth$wdi_GDPcap_lag) & !is.na (bmonth$wdi_GDPcap_lag) & !is.na (bmonth$wdi_GDPcapGrowth_lag) & !is.na (bmonth$pop_lag) & !is.na (bmonth$physint_lag) & !is.na (bmonth$polity),]$countryYear))
                             , NmonthsCont01e$N))
(nmonthsN80001controls <- c (length (unique (bmonth[!is.na (bmonth$n800_d45_wequal_any) & !is.na (bmonth$wdi_GDPcap_lag) & !is.na (bmonth$wdi_GDPcap_lag) & !is.na (bmonth$wdi_GDPcapGrowth_lag) & !is.na (bmonth$pop_lag) & !is.na (bmonth$physint_lag) & !is.na (bmonth$polity),]$country))
                             , length (unique (bmonth[!is.na (bmonth$n800_d45_wequal_any) & !is.na (bmonth$wdi_GDPcap_lag) & !is.na (bmonth$wdi_GDPcap_lag) & !is.na (bmonth$wdi_GDPcapGrowth_lag) & !is.na (bmonth$pop_lag) & !is.na (bmonth$physint_lag) & !is.na (bmonth$polity),]$countryYear))
                             , NmonthsN80001e$N))
(nmonthsUNReg01controls <- c (length (unique (bmonth[!is.na (bmonth$nUN_d45_wequal_any) & !is.na (bmonth$wdi_GDPcap_lag) & !is.na (bmonth$wdi_GDPcap_lag) & !is.na (bmonth$wdi_GDPcapGrowth_lag) & !is.na (bmonth$pop_lag) & !is.na (bmonth$physint_lag) & !is.na (bmonth$polity),]$country))
                              , length (unique (bmonth[!is.na (bmonth$nUN_d45_wequal_any) & !is.na (bmonth$wdi_GDPcap_lag) & !is.na (bmonth$wdi_GDPcap_lag) & !is.na (bmonth$wdi_GDPcapGrowth_lag) & !is.na (bmonth$pop_lag) & !is.na (bmonth$physint_lag) & !is.na (bmonth$polity),]$countryYear))
                              , NmonthsUNReg01e$N))

# running the models
v <- NULL
mRob11m01 <- mRob11m02 <- mRob11m03 <- mRob11m04 <- list () ## we'll put the models here

system.time (
  for (v in 1:length (vRob11m02)){
    
    ## defining the explanatory variable of interest
    bmonth$iv01 <- bmonth[,vRob11m01[v]]
    bmonth$iv02 <- bmonth[,vRob11m02[v]]
    bmonth$iv03 <- bmonth[,vRob11m03[v]]
    bmonth$iv04 <- bmonth[,vRob11m04[v]]
    
    
    ## (i) 4-month time frame
    
    # neither FEs nor clustered SEs
    mRob11m01[[v+0*length (vRob11m01)]] <- summary (felm (pbega2 ~ iv01 | 0 | 0 | 0, data=bmonth))$coef
    mRob11m01[[v+1*length (vRob11m01)]] <- summary (felm (pbega2 ~ iv01 + ele01b | 0 | 0 | 0, data=bmonth))$coef
    
    # no FEs but SEs clustered by COUNTRY
    mRob11m01[[v+2*length (vRob11m01)]] <- summary (felm (pbega2 ~ iv01 | 0 | 0 | country, data=bmonth))$coef
    mRob11m01[[v+3*length (vRob11m01)]] <- summary (felm (pbega2 ~ iv01 + ele01b | 0 | 0 | country, data=bmonth))$coef
    
    # no FEs but SEs clustered by COUNTRY + controls
    mRob11m01[[v+4*length (vRob11m01)]] <- summary (felm (pbega2 ~ iv01 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bmonth))$coef
    mRob11m01[[v+5*length (vRob11m01)]] <- summary (felm (pbega2 ~ iv01 + ele01b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bmonth))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY
    mRob11m01[[v+6*length (vRob11m01)]] <- summary (felm (pbega2 ~ iv01 | country | 0 | country, data=bmonth))$coef
    mRob11m01[[v+7*length (vRob11m01)]] <- summary (felm (pbega2 ~ iv01 + ele01b | country | 0 | country, data=bmonth))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY + Controls
    mRob11m01[[v+8*length (vRob11m01)]] <- summary (felm (pbega2 ~ iv01 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bmonth))$coef
    mRob11m01[[v+9*length (vRob11m01)]] <- summary (felm (pbega2 ~ iv01 + ele01b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bmonth))$coef
    
    # FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob11m01[[v+10*length (vRob11m01)]] <- summary (felm (pbega2 ~ iv01 | countryYear | 0 | country, data=bmonth))$coef
    mRob11m01[[v+11*length (vRob11m01)]] <- summary (felm (pbega2 ~ iv01 + ele01b | countryYear | 0 | country, data=bmonth))$coef
    
    # REs by COUNTRY, standard SEs
    mRob11m01[[v+12*length (vRob11m01)]] <- summary (glmer (pbega ~ iv01 + (1|country), family=binomial(link="logit"), data=bmonth))$coef
    mRob11m01[[v+13*length (vRob11m01)]] <- summary (glmer (pbega ~ iv01 + ele01b + (1|country), family=binomial(link="logit"), data=bmonth))$coef
    
    # REs by COUNTRY-YEAR, standars SEs
    mRob11m01[[v+14*length (vRob11m01)]] <- summary (glmer (pbega ~ iv01 + (1|countryYear), family=binomial(link="logit"), data=bmonth))$coef
    mRob11m01[[v+15*length (vRob11m01)]] <- summary (glmer (pbega ~ iv01 + ele01b + (1|countryYear), family=binomial(link="logit"), data=bmonth))$coef
    
    
    ## (ii) 6-month time frame
    
    # neither FEs nor clustered SEs
    mRob11m02[[v+0*length (vRob11m02)]] <- summary (felm (pbega2 ~ iv02 | 0 | 0 | 0, data=bmonth))$coef
    mRob11m02[[v+1*length (vRob11m02)]] <- summary (felm (pbega2 ~ iv02 + ele02b | 0 | 0 | 0, data=bmonth))$coef
    
    # no FEs but SEs clustered by COUNTRY
    mRob11m02[[v+2*length (vRob11m02)]] <- summary (felm (pbega2 ~ iv02 | 0 | 0 | country, data=bmonth))$coef
    mRob11m02[[v+3*length (vRob11m02)]] <- summary (felm (pbega2 ~ iv02 + ele02b | 0 | 0 | country, data=bmonth))$coef
    
    # no FEs but SEs clustered by COUNTRY + controls
    mRob11m02[[v+4*length (vRob11m02)]] <- summary (felm (pbega2 ~ iv02 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bmonth))$coef
    mRob11m02[[v+5*length (vRob11m02)]] <- summary (felm (pbega2 ~ iv02 + ele02b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bmonth))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY
    mRob11m02[[v+6*length (vRob11m02)]] <- summary (felm (pbega2 ~ iv02 | country | 0 | country, data=bmonth))$coef
    mRob11m02[[v+7*length (vRob11m02)]] <- summary (felm (pbega2 ~ iv02 + ele02b | country | 0 | country, data=bmonth))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY + Controls
    mRob11m02[[v+8*length (vRob11m02)]] <- summary (felm (pbega2 ~ iv02 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bmonth))$coef
    mRob11m02[[v+9*length (vRob11m02)]] <- summary (felm (pbega2 ~ iv02 + ele02b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bmonth))$coef
    
    # FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob11m02[[v+10*length (vRob11m02)]] <- summary (felm (pbega2 ~ iv02 | countryYear | 0 | country, data=bmonth))$coef
    mRob11m02[[v+11*length (vRob11m02)]] <- summary (felm (pbega2 ~ iv02 + ele02b | countryYear | 0 | country, data=bmonth))$coef
    
        # REs by COUNTRY, standard SEs
    mRob11m02[[v+12*length (vRob11m02)]] <- summary (glmer (pbega ~ iv02 + (1|country), family=binomial(link="logit"), data=bmonth))$coef
    mRob11m02[[v+13*length (vRob11m02)]] <- summary (glmer (pbega ~ iv02 + ele02b + (1|country), family=binomial(link="logit"), data=bmonth))$coef
    
    # REs by COUNTRY-YEAR, standars SEs
    mRob11m02[[v+14*length (vRob11m02)]] <- summary (glmer (pbega ~ iv02 + (1|countryYear), family=binomial(link="logit"), data=bmonth))$coef
    mRob11m02[[v+15*length (vRob11m02)]] <- summary (glmer (pbega ~ iv02 + ele02b + (1|countryYear), family=binomial(link="logit"), data=bmonth))$coef
    
    
    ## (iii) 12-month time frame
    
    # neither FEs nor clustered SEs
    mRob11m03[[v+0*length (vRob11m03)]] <- summary (felm (pbega2 ~ iv03 | 0 | 0 | 0, data=bmonth))$coef
    mRob11m03[[v+1*length (vRob11m03)]] <- summary (felm (pbega2 ~ iv03 + ele03b | 0 | 0 | 0, data=bmonth))$coef
    
    # no FEs but SEs clustered by COUNTRY
    mRob11m03[[v+2*length (vRob11m03)]] <- summary (felm (pbega2 ~ iv03 | 0 | 0 | country, data=bmonth))$coef
    mRob11m03[[v+3*length (vRob11m03)]] <- summary (felm (pbega2 ~ iv03 + ele03b | 0 | 0 | country, data=bmonth))$coef
    
    # no FEs but SEs clustered by COUNTRY + controls
    mRob11m03[[v+4*length (vRob11m03)]] <- summary (felm (pbega2 ~ iv03 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bmonth))$coef
    mRob11m03[[v+5*length (vRob11m03)]] <- summary (felm (pbega2 ~ iv03 + ele03b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bmonth))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY
    mRob11m03[[v+6*length (vRob11m03)]] <- summary (felm (pbega2 ~ iv03 | country | 0 | country, data=bmonth))$coef
    mRob11m03[[v+7*length (vRob11m03)]] <- summary (felm (pbega2 ~ iv03 + ele03b | country | 0 | country, data=bmonth))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY + Controls
    mRob11m03[[v+8*length (vRob11m03)]] <- summary (felm (pbega2 ~ iv03 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bmonth))$coef
    mRob11m03[[v+9*length (vRob11m03)]] <- summary (felm (pbega2 ~ iv03 + ele03b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bmonth))$coef
    
    # FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob11m03[[v+10*length (vRob11m03)]] <- summary (felm (pbega2 ~ iv03 | countryYear | 0 | country, data=bmonth))$coef
    mRob11m03[[v+11*length (vRob11m03)]] <- summary (felm (pbega2 ~ iv03 + ele03b | countryYear | 0 | country, data=bmonth))$coef
    
    # REs by COUNTRY, standard SEs
    mRob11m03[[v+12*length (vRob11m03)]] <- summary (glmer (pbega ~ iv03 + (1|country), family=binomial(link="logit"), data=bmonth))$coef
    mRob11m03[[v+13*length (vRob11m03)]] <- summary (glmer (pbega ~ iv03 + ele03b + (1|country), family=binomial(link="logit"), data=bmonth))$coef
    
    # REs by COUNTRY-YEAR, standars SEs
    mRob11m03[[v+14*length (vRob11m03)]] <- summary (glmer (pbega ~ iv03 + (1|countryYear), family=binomial(link="logit"), data=bmonth))$coef
    mRob11m03[[v+15*length (vRob11m03)]] <- summary (glmer (pbega ~ iv03 + ele03b + (1|countryYear), family=binomial(link="logit"), data=bmonth))$coef
    
    
    ## (iv) 18-month time frame
    
    # neither FEs nor clustered SEs
    mRob11m04[[v+0*length (vRob11m04)]] <- summary (felm (pbega2 ~ iv04 | 0 | 0 | 0, data=bmonth))$coef
    mRob11m04[[v+1*length (vRob11m04)]] <- summary (felm (pbega2 ~ iv04 + ele04b | 0 | 0 | 0, data=bmonth))$coef
    
    # no FEs but SEs clustered by COUNTRY
    mRob11m04[[v+2*length (vRob11m04)]] <- summary (felm (pbega2 ~ iv04 | 0 | 0 | country, data=bmonth))$coef
    mRob11m04[[v+3*length (vRob11m04)]] <- summary (felm (pbega2 ~ iv04 + ele04b | 0 | 0 | country, data=bmonth))$coef
    
    # no FEs but SEs clustered by COUNTRY + controls
    mRob11m04[[v+4*length (vRob11m04)]] <- summary (felm (pbega2 ~ iv04 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bmonth))$coef
    mRob11m04[[v+5*length (vRob11m04)]] <- summary (felm (pbega2 ~ iv04 + ele04b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=bmonth))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY
    mRob11m04[[v+6*length (vRob11m04)]] <- summary (felm (pbega2 ~ iv04 | country | 0 | country, data=bmonth))$coef
    mRob11m04[[v+7*length (vRob11m04)]] <- summary (felm (pbega2 ~ iv04 + ele04b | country | 0 | country, data=bmonth))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY + Controls
    mRob11m04[[v+8*length (vRob11m04)]] <- summary (felm (pbega2 ~ iv04 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bmonth))$coef
    mRob11m04[[v+9*length (vRob11m04)]] <- summary (felm (pbega2 ~ iv04 + ele04b + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=bmonth))$coef
    
    # FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob11m04[[v+10*length (vRob11m04)]] <- summary (felm (pbega2 ~ iv04 | countryYear | 0 | country, data=bmonth))$coef
    mRob11m04[[v+11*length (vRob11m04)]] <- summary (felm (pbega2 ~ iv04 + ele04b | countryYear | 0 | country, data=bmonth))$coef
    
    # REs by COUNTRY, standard SEs
    mRob11m04[[v+12*length (vRob11m04)]] <- summary (glmer (pbega ~ iv04 + (1|country), family=binomial(link="logit"), data=bmonth))$coef
    mRob11m04[[v+13*length (vRob11m04)]] <- summary (glmer (pbega ~ iv04 + ele04b + (1|country), family=binomial(link="logit"), data=bmonth))$coef
    
    # REs by COUNTRY-YEAR, standars SEs
    mRob11m04[[v+14*length (vRob11m04)]] <- summary (glmer (pbega ~ iv04 + (1|countryYear), family=binomial(link="logit"), data=bmonth))$coef
    mRob11m04[[v+15*length (vRob11m04)]] <- summary (glmer (pbega ~ iv04 + ele04b + (1|countryYear), family=binomial(link="logit"), data=bmonth))$coef
  }
) ## 4083 seconds


## (3.2.6) Robustness checks: Yearly data

# listing the explanatory variables
vRob12y01 <- c ("n50_y01_wequal_any", "n50_y01_wequal_sum", "n50_y01_wSize_any"
                , "n800_y01_wequal_any", "n800_y01_wequal_sum", "n800_y01_wSize_any"
                , "nUN_y01_wequal_any", "nUN_y01_wequal_sum", "nUN_y01_wSize_any")

# running one model to get the number of observations
(sumNyearsCont01a <- summary (NyearsCont01a <- felm (pbega2 ~ n50_y01_wequal_any | 0 | 0 | 0, data=byear)))
(sumNyearsCont01b <- summary (NyearsCont01b <- felm (pbega2 ~ n50_y01_wequal_any | country | 0 | 0, data=byear)))
(sumNyearsCont01c <- summary (NyearsCont01c <- felm (pbega2 ~ n50_y01_wequal_any | 0 | 0 | country, data=byear)))
(sumNyearsCont01d <- summary (NyearsCont01d <- felm (pbega2 ~ n50_y01_wequal_any | country | 0 | country, data=byear)))
(sumNyearsCont01e <- summary (NyearsCont01e <- felm (pbega2 ~ n50_y01_wequal_any + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=byear)))

(sumNyearsN80001a <- summary (NyearsN80001a <- felm (pbega2 ~ n800_y01_wequal_any | 0 | 0 | 0, data=byear)))
(sumNyearsN80001b <- summary (NyearsN80001b <- felm (pbega2 ~ n800_y01_wequal_any | country | 0 | 0, data=byear)))
(sumNyearsN80001c <- summary (NyearsN80001c <- felm (pbega2 ~ n800_y01_wequal_any | 0 | 0 | country, data=byear)))
(sumNyearsN80001d <- summary (NyearsN80001d <- felm (pbega2 ~ n800_y01_wequal_any | country | 0 | country, data=byear)))
(sumNyearsN80001e <- summary (NyearsN80001e <- felm (pbega2 ~ n800_y01_wequal_any + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=byear)))

(sumNyearsUNReg01a <- summary (NyearsUNReg01a <- felm (pbega2 ~ nUN_y01_wequal_any | 0 | 0 | 0, data=byear)))
(sumNyearsUNReg01b <- summary (NyearsUNReg01b <- felm (pbega2 ~ nUN_y01_wequal_any | country | 0 | 0, data=byear)))
(sumNyearsUNReg01c <- summary (NyearsUNReg01c <- felm (pbega2 ~ nUN_y01_wequal_any | 0 | 0 | country, data=byear)))
(sumNyearsUNReg01d <- summary (NyearsUNReg01d <- felm (pbega2 ~ nUN_y01_wequal_any | country | 0 | country, data=byear)))
(sumNyearsUNReg01e <- summary (NyearsUNReg01e <- felm (pbega2 ~ nUN_y01_wequal_any + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=byear)))

# getting the number of observations
(nyearsCont01main <- c (length (unique (byear[!is.na (byear$n50_y01_wequal_any),]$country))
                        , length (unique (NyearsCont01d$fe$country))
                        , NyearsCont01d$N))
(nyearsN80001main <- c (length (unique (byear[!is.na (byear$n800_y01_wequal_any),]$country))
                        , length (unique (NyearsN80001d$fe$country))
                        , NyearsN80001d$N))
(nyearsUNReg01main <- c (length (unique (byear[!is.na (byear$nUN_y01_wequal_any),]$country))
                         , length (unique (NyearsUNReg01d$fe$country))
                         , NyearsUNReg01d$N))

(nyearsCont01controls <- c (length (unique (byear[!is.na (byear$n50_y01_wequal_any) & !is.na (byear$wdi_GDPcap_lag) & !is.na (byear$wdi_GDPcap_lag) & !is.na (byear$wdi_GDPcapGrowth_lag) & !is.na (byear$pop_lag) & !is.na (byear$physint_lag) & !is.na (byear$polity),]$country))
                            , length (unique (byear[!is.na (byear$n50_y01_wequal_any) & !is.na (byear$wdi_GDPcap_lag) & !is.na (byear$wdi_GDPcap_lag) & !is.na (byear$wdi_GDPcapGrowth_lag) & !is.na (byear$pop_lag) & !is.na (byear$physint_lag) & !is.na (byear$polity),]$country))
                            , NyearsCont01e$N))
(nyearsN80001controls <- c (length (unique (byear[!is.na (byear$n800_y01_wequal_any) & !is.na (byear$wdi_GDPcap_lag) & !is.na (byear$wdi_GDPcap_lag) & !is.na (byear$wdi_GDPcapGrowth_lag) & !is.na (byear$pop_lag) & !is.na (byear$physint_lag) & !is.na (byear$polity),]$country))
                            , length (unique (byear[!is.na (byear$n800_y01_wequal_any) & !is.na (byear$wdi_GDPcap_lag) & !is.na (byear$wdi_GDPcap_lag) & !is.na (byear$wdi_GDPcapGrowth_lag) & !is.na (byear$pop_lag) & !is.na (byear$physint_lag) & !is.na (byear$polity),]$country))
                            , NyearsN80001e$N))
(nyearsUNReg01controls <- c (length (unique (byear[!is.na (byear$nUN_y01_wequal_any) & !is.na (byear$wdi_GDPcap_lag) & !is.na (byear$wdi_GDPcap_lag) & !is.na (byear$wdi_GDPcapGrowth_lag) & !is.na (byear$pop_lag) & !is.na (byear$physint_lag) & !is.na (byear$polity),]$country))
                             , length (unique (byear[!is.na (byear$nUN_y01_wequal_any) & !is.na (byear$wdi_GDPcap_lag) & !is.na (byear$wdi_GDPcap_lag) & !is.na (byear$wdi_GDPcapGrowth_lag) & !is.na (byear$pop_lag) & !is.na (byear$physint_lag) & !is.na (byear$polity),]$country))
                             , NyearsUNReg01e$N))

# doing the loop
v <- NULL
mRob12y01 <- list () ## we'll put the models here

system.time (
  for (v in 1:length (vRob12y01)){
    
    ## defining the explanatory variable of interest
    byear$iv01 <- byear[,vRob12y01[v]]
    
    
    ## 1-year time frame only
    
    # neither FEs nor clustered SEs
    mRob12y01[[v+0*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 | 0 | 0 | 0, data=byear))$coef
    mRob12y01[[v+1*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 + eleLag01 | 0 | 0 | 0, data=byear))$coef
    
    # no FEs but SEs clustered by COUNTRY
    mRob12y01[[v+2*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 | 0 | 0 | country, data=byear))$coef
    mRob12y01[[v+3*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 + eleLag01 | 0 | 0 | country, data=byear))$coef
    
    # neither FEs nor clustered SEs + controls
    mRob12y01[[v+4*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | 0, data=byear))$coef
    mRob12y01[[v+5*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 + eleLag01 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | 0, data=byear))$coef
    
    # no FEs but SEs clustered by COUNTRY + controls
    mRob12y01[[v+6*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=byear))$coef
    mRob12y01[[v+7*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 + eleLag01 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | 0 | 0 | country, data=byear))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY
    mRob12y01[[v+8*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 | country | 0 | country, data=byear))$coef
    mRob12y01[[v+9*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 + eleLag01 | country | 0 | country, data=byear))$coef
    
    # FEs by COUNTRY and SEs clustered by COUNTRY + Controls
    mRob12y01[[v+10*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=byear))$coef
    mRob12y01[[v+11*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 + eleLag01 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country | 0 | country, data=byear))$coef
    
    # FEs by COUNTRY and YEAR and SEs clustered by COUNTRY
    mRob12y01[[v+12*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 | country + year | 0 | country, data=byear))$coef
    mRob12y01[[v+13*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 + eleLag01 | country + year | 0 | country, data=byear))$coef
    
    # FEs by COUNTRY and YEAR and SEs clustered by COUNTRY + Controls
    mRob12y01[[v+14*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country + year | 0 | country, data=byear))$coef
    mRob12y01[[v+15*length (vRob12y01)]] <- summary (felm (pbega2 ~ iv01 + eleLag01 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity | country + year | 0 | country, data=byear))$coef
    
    # REs by COUNTRY, standard SEs
    mRob12y01[[v+16*length (vRob12y01)]] <- summary (glmer (pbega ~ iv01 + (1|country), family=binomial(link="logit"), data=byear))$coef
    mRob12y01[[v+17*length (vRob12y01)]] <- summary (glmer (pbega ~ iv01 + eleLag01 + (1|country), family=binomial(link="logit"), data=byear))$coef
    
    # REs by COUNTRY, standard SEs + controls
    mRob12y01[[v+18*length (vRob12y01)]] <- summary (glmer (pbega ~ iv01 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity + (1|country), family=binomial(link="logit"), data=byear))$coef
    mRob12y01[[v+19*length (vRob12y01)]] <- summary (glmer (pbega ~ iv01 + eleLag01 + wdi_GDPcap_lag + wdi_GDPcapGrowth_lag + pop_lag + physint_lag + polity + (1|country), family=binomial(link="logit"), data=byear))$coef
  }
) ## 143 seconds


## (3.2.7) Robustness checks: Including the 2007 Venezuelan protests

# listing the explanatory variables
vContRob16 <- c ("n50_d45_wequal_any", "n50_d90_wequal_any", "n50_d120_wequal_any"
                 , "n50_d45_wequal_sum", "n50_d90_wequal_sum", "n50_d120_wequal_sum"
                 , "n50_d45_wSize_any", "n50_d90_wSize_any", "n50_d120_wSize_any")
vN800Rob16 <- c ("n800_d45_wequal_any", "n800_d90_wequal_any", "n800_d120_wequal_any"
                 , "n800_d45_wequal_sum", "n800_d90_wequal_sum", "n800_d120_wequal_sum"
                 , "n800_d45_wSize_any", "n800_d90_wSize_any", "n800_d120_wSize_any")
vUNRegRob16 <- c ("nUN_d45_wequal_any", "nUN_d90_wequal_any", "nUN_d120_wequal_any"
                  , "nUN_d45_wequal_sum", "nUN_d90_wequal_sum", "nUN_d120_wequal_sum"
                  , "nUN_d45_wSize_any", "nUN_d90_wSize_any", "nUN_d120_wSize_any")

# running one model to get the number of observations
(sumNobsContRob16a <- summary (NobsContRob16a <- felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=vzla)))
(sumNobsN800Rob16a <- summary (NobsN800Rob16a <- felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=vzla)))
(sumNobsUNRegRob16a <- summary (NobsUNRegRob16a <- felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=vzla)))

# getting the number of observations
(nobsContRob16 <- c (length (unique (vzla[!is.na (vzla$n50_d45_wequal_any),]$country))
                         , length (unique (NobsContRob16a$fe$countryYear))
                         , NobsContRob16a$N))
(nobsN800Rob16 <- c (length (unique (vzla[!is.na (vzla$n800_d45_wequal_any),]$country))
                         , length (unique (NobsN800Rob16a$fe$countryYear))
                         , NobsN800Rob16a$N))
(nobsUNRegRob16 <- c (length (unique (vzla[!is.na (vzla$nUN_d45_wequal_any),]$country))
                          , length (unique (NobsUNRegRob16a$fe$countryYear))
                          , NobsUNRegRob16a$N))

# doing the loop
v <- NULL
mContRob16 <- mN800Rob16 <- mUNRegRob16 <- list ()

system.time (
  for (v in 1:length (vContRob16)){
    
    # defining the explanatory variable of interest
    vzla$ivCont <- vzla[,vContRob16[v]]
    vzla$ivN800 <- vzla[,vN800Rob16[v]]
    vzla$ivUNReg <- vzla[,vUNRegRob16[v]]
    
    ## (i) Contiguous neighbors
    
    # country-year FEs
    mContRob16[[v+0*length (vContRob16)]] <- summary (felm (pbega2 ~ ivCont | countryYear | 0 | country, data=vzla))$coef
    mContRob16[[v+1*length (vContRob16)]] <- summary (felm (pbega2 ~ ivCont + ele30 | countryYear | 0 | country, data=vzla))$coef
    
    
    ## (ii) 800km neighbors
    
    # country-year FEs
    mN800Rob16[[v+0*length (vN800Rob16)]] <- summary (felm (pbega2 ~ ivN800 | countryYear | 0 | country, data=vzla))$coef
    mN800Rob16[[v+1*length (vN800Rob16)]] <- summary (felm (pbega2 ~ ivN800 + ele30 | countryYear | 0 | country, data=vzla))$coef
    
    ## (iii) UN region neighbors
    
    # country-year FEs
    mUNRegRob16[[v+0*length (vUNRegRob16)]] <- summary (felm (pbega2 ~ ivUNReg | countryYear | 0 | country, data=vzla))$coef
    mUNRegRob16[[v+1*length (vUNRegRob16)]] <- summary (felm (pbega2 ~ ivUNReg + ele30 | countryYear | 0 | country, data=vzla))$coef
    }) ## 226 seconds


## (3.2.8) Alternative protest measure (I): GDELT data

# listing the explanatory variables
vContRob02 <- c ("n50_d45_wequalGdelt_any", "n50_d90_wequalGdelt_any", "n50_d120_wequalGdelt_any"
                 , "n50_d45_wequalGdelt_sum", "n50_d90_wequalGdelt_sum", "n50_d120_wequalGdelt_sum")
vN800Rob02 <- c ("n800_d45_wequalGdelt_any", "n800_d90_wequalGdelt_any", "n800_d120_wequalGdelt_any"
                 , "n800_d45_wequalGdelt_sum", "n800_d90_wequalGdelt_sum", "n800_d120_wequalGdelt_sum")
vUNRegRob02 <- c ("nUN_d45_wequalGdelt_any", "nUN_d90_wequalGdelt_any", "nUN_d120_wequalGdelt_any"
                  , "nUN_d45_wequalGdelt_sum", "nUN_d90_wequalGdelt_sum", "nUN_d120_wequalGdelt_sum")

# running one model to get the number of observations
(sumNobsContRob02a.high <- summary (NobsContRob02a.high <- felm (pbeg_gdelt2 ~ n50_d45_wequalGdelt_any | 0 | 0 | 0, data=gdelt)))
(sumNobsContRob02b.high <- summary (NobsContRob02b.high <- felm (pbeg_gdelt2 ~ n50_d45_wequalGdelt_any | countryYear | 0 | 0, data=gdelt)))
(sumNobsContRob02c.high <- summary (NobsContRob02c.high <- felm (pbeg_gdelt2 ~ n50_d45_wequalGdelt_any | 0 | 0 | country, data=gdelt)))
(sumNobsContRob02d.high <- summary (NobsContRob02d.high <- felm (pbeg_gdelt2 ~ n50_d45_wequalGdelt_any | countryYear | 0 | country, data=gdelt)))
(sumNobsContRob02a.low <- summary (NobsContRob02a.low <- felm (pbeg_gdelt2 ~ n50_d45_wequalGdelt_any | 0 | 0 | 0, data=gdelt[gdelt$year < 2011,])))
(sumNobsContRob02b.low <- summary (NobsContRob02b.low <- felm (pbeg_gdelt2 ~ n50_d45_wequalGdelt_any | countryYear | 0 | 0, data=gdelt[gdelt$year < 2011,])))
(sumNobsContRob02c.low <- summary (NobsContRob02c.low <- felm (pbeg_gdelt2 ~ n50_d45_wequalGdelt_any | 0 | 0 | country, data=gdelt[gdelt$year < 2011,])))
(sumNobsContRob02d.low <- summary (NobsContRob02d.low <- felm (pbeg_gdelt2 ~ n50_d45_wequalGdelt_any | countryYear | 0 | country, data=gdelt[gdelt$year < 2011,])))

(sumNobsN800Rob02a.high <- summary (NobsN800Rob02a.high <- felm (pbeg_gdelt2 ~ n800_d45_wequalGdelt_any | 0 | 0 | 0, data=gdelt)))
(sumNobsN800Rob02b.high <- summary (NobsN800Rob02b.high <- felm (pbeg_gdelt2 ~ n800_d45_wequalGdelt_any | countryYear | 0 | 0, data=gdelt)))
(sumNobsN800Rob02c.high <- summary (NobsN800Rob02c.high <- felm (pbeg_gdelt2 ~ n800_d45_wequalGdelt_any | 0 | 0 | country, data=gdelt)))
(sumNobsN800Rob02d.high <- summary (NobsN800Rob02d.high <- felm (pbeg_gdelt2 ~ n800_d45_wequalGdelt_any | countryYear | 0 | country, data=gdelt)))
(sumNobsN800Rob02a.low <- summary (NobsN800Rob02a.low <- felm (pbeg_gdelt2 ~ n800_d45_wequalGdelt_any | 0 | 0 | 0, data=gdelt[gdelt$year < 2011,])))
(sumNobsN800Rob02b.low <- summary (NobsN800Rob02b.low <- felm (pbeg_gdelt2 ~ n800_d45_wequalGdelt_any | countryYear | 0 | 0, data=gdelt[gdelt$year < 2011,])))
(sumNobsN800Rob02c.low <- summary (NobsN800Rob02c.low <- felm (pbeg_gdelt2 ~ n800_d45_wequalGdelt_any | 0 | 0 | country, data=gdelt[gdelt$year < 2011,])))
(sumNobsN800Rob02d.low <- summary (NobsN800Rob02d.low <- felm (pbeg_gdelt2 ~ n800_d45_wequalGdelt_any | countryYear | 0 | country, data=gdelt[gdelt$year < 2011,])))

(sumNobsUNRegRob02a.high <- summary (NobsUNRegRob02a.high <- felm (pbeg_gdelt2 ~ nUN_d45_wequalGdelt_any | 0 | 0 | 0, data=gdelt)))
(sumNobsUNRegRob02b.high <- summary (NobsUNRegRob02b.high <- felm (pbeg_gdelt2 ~ nUN_d45_wequalGdelt_any | countryYear | 0 | 0, data=gdelt)))
(sumNobsUNRegRob02c.high <- summary (NobsUNRegRob02c.high <- felm (pbeg_gdelt2 ~ nUN_d45_wequalGdelt_any | 0 | 0 | country, data=gdelt)))
(sumNobsUNRegRob02d.high <- summary (NobsUNRegRob02d.high <- felm (pbeg_gdelt2 ~ nUN_d45_wequalGdelt_any | countryYear | 0 | country, data=gdelt)))
(sumNobsUNRegRob02a.low <- summary (NobsUNRegRob02a.low <- felm (pbeg_gdelt2 ~ nUN_d45_wequalGdelt_any | 0 | 0 | 0, data=gdelt[gdelt$year < 2011,])))
(sumNobsUNRegRob02b.low <- summary (NobsUNRegRob02b.low <- felm (pbeg_gdelt2 ~ nUN_d45_wequalGdelt_any | countryYear | 0 | 0, data=gdelt[gdelt$year < 2011,])))
(sumNobsUNRegRob02c.low <- summary (NobsUNRegRob02c.low <- felm (pbeg_gdelt2 ~ nUN_d45_wequalGdelt_any | 0 | 0 | country, data=gdelt[gdelt$year < 2011,])))
(sumNobsUNRegRob02d.low <- summary (NobsUNRegRob02d.low <- felm (pbeg_gdelt2 ~ nUN_d45_wequalGdelt_any | countryYear | 0 | country, data=gdelt[gdelt$year < 2011,])))

# getting the number of observations
(nobsContRob02.low <- c (length (unique (gdelt[!is.na (gdelt$n50_d45_wequalGdelt_any) & gdelt$year < 2011,]$country))
                         , length (unique (NobsContRob02d.low$fe$countryYear))
                         , NobsContRob02d.low$N))
(nobsN800Rob02.low <- c (length (unique (gdelt[!is.na (gdelt$n800_d45_wequalGdelt_any) & gdelt$year < 2011,]$country))
                         , length (unique (NobsN800Rob02d.low$fe$countryYear))
                         , NobsN800Rob02d.low$N))
(nobsUNRegRob02.low <- c (length (unique (gdelt[!is.na (gdelt$nUN_d45_wequalGdelt_any) & gdelt$year < 2011,]$country))
                          , length (unique (NobsUNRegRob02d.low$fe$countryYear))
                          , NobsUNRegRob02d.low$N))
(nobsContRob02.high <- c (length (unique (gdelt[!is.na (gdelt$n50_d45_wequalGdelt_any),]$country))
                          , length (unique (NobsContRob02d.high$fe$countryYear))
                          , NobsContRob02d.high$N))
(nobsN800Rob02.high <- c (length (unique (gdelt[!is.na (gdelt$n800_d45_wequalGdelt_any),]$country))
                          , length (unique (NobsN800Rob02d.high$fe$countryYear))
                          , NobsN800Rob02d.high$N))
(nobsUNRegRob02.high <- c (length (unique (gdelt[!is.na (gdelt$nUN_d45_wequalGdelt_any),]$country))
                           , length (unique (NobsUNRegRob02d.high$fe$countryYear))
                           , NobsUNRegRob02d.high$N))

# doing the loop
v <- NULL
mContRob02 <- mN800Rob02 <- mUNRegRob02 <- list ()

system.time (
  for (v in 1:length (vContRob02)){
    
    ## defining the explanatory variable of interest
    gdelt$ivCont <- gdelt[,vContRob02[v]]
    gdelt$ivN800 <- gdelt[,vN800Rob02[v]]
    gdelt$ivUNReg <- gdelt[,vUNRegRob02[v]]
    
    ## (i) Contiguous neighbors
    
    # country-year FEs
    mContRob02[[v+0*length (vContRob02)]] <- summary (felm (pbeg_gdelt2 ~ ivCont | countryYear | 0 | country, data=gdelt))$coef
    mContRob02[[v+1*length (vContRob02)]] <- summary (felm (pbeg_gdelt2 ~ ivCont + ele30 | countryYear | 0 | country, data=gdelt))$coef
    mContRob02[[v+2*length (vContRob02)]] <- summary (felm (pbeg_gdelt2 ~ ivCont | countryYear | 0 | country, data=gdelt[gdelt$year < 2011,]))$coef
    mContRob02[[v+3*length (vContRob02)]] <- summary (felm (pbeg_gdelt2 ~ ivCont + ele30 | countryYear | 0 | country, data=gdelt[gdelt$year < 2011,]))$coef
    
    
    ## (ii) 800km neighbors
    
    # country-year FEs
    mN800Rob02[[v+0*length (vN800Rob02)]] <- summary (felm (pbeg_gdelt2 ~ ivN800 | countryYear | 0 | country, data=gdelt))$coef
    mN800Rob02[[v+1*length (vN800Rob02)]] <- summary (felm (pbeg_gdelt2 ~ ivN800 + ele30 | countryYear | 0 | country, data=gdelt))$coef
    mN800Rob02[[v+2*length (vN800Rob02)]] <- summary (felm (pbeg_gdelt2 ~ ivN800 | countryYear | 0 | country, data=gdelt[gdelt$year < 2011,]))$coef
    mN800Rob02[[v+3*length (vN800Rob02)]] <- summary (felm (pbeg_gdelt2 ~ ivN800 + ele30 | countryYear | 0 | country, data=gdelt[gdelt$year < 2011,]))$coef
    
    
    ## (iii) UN region neighbors
    
    # country-year FEs
    mUNRegRob02[[v+0*length (vUNRegRob02)]] <- summary (felm (pbeg_gdelt2 ~ ivUNReg | countryYear | 0 | country, data=gdelt))$coef
    mUNRegRob02[[v+1*length (vUNRegRob02)]] <- summary (felm (pbeg_gdelt2 ~ ivUNReg + ele30 | countryYear | 0 | country, data=gdelt))$coef
    mUNRegRob02[[v+2*length (vUNRegRob02)]] <- summary (felm (pbeg_gdelt2 ~ ivUNReg | countryYear | 0 | country, data=gdelt[gdelt$year < 2011,]))$coef
    mUNRegRob02[[v+3*length (vUNRegRob02)]] <- summary (felm (pbeg_gdelt2 ~ ivUNReg + ele30 | countryYear | 0 | country, data=gdelt[gdelt$year < 2011,]))$coef
  }
) ## 321 seconds


## (3.2.9) Alternative protest measure (II): SPEED data

# listing the explanatory variables
vContRob03 <- c ("n50_d45_wequalSPEED_any", "n50_d90_wequalSPEED_any", "n50_d120_wequalSPEED_any"
                 , "n50_d45_wequalSPEED_sum", "n50_d90_wequalSPEED_sum", "n50_d120_wequalSPEED_sum")
vN800Rob03 <- c ("n800_d45_wequalSPEED_any", "n800_d90_wequalSPEED_any", "n800_d120_wequalSPEED_any"
                 , "n800_d45_wequalSPEED_sum", "n800_d90_wequalSPEED_sum", "n800_d120_wequalSPEED_sum")
vUNRegRob03 <- c ("nUN_d45_wequalSPEED_any", "nUN_d90_wequalSPEED_any", "nUN_d120_wequalSPEED_any"
                  , "nUN_d45_wequalSPEED_sum", "nUN_d90_wequalSPEED_sum", "nUN_d120_wequalSPEED_sum")

# running one model to get the number of observations
(sumNobsContRob03a <- summary (NobsContRob03a <- felm (pbegSpeed2 ~ n50_d45_wequalSPEED_any | 0 | 0 | 0, data=speed)))
(sumNobsContRob03b <- summary (NobsContRob03b <- felm (pbegSpeed2 ~ n50_d45_wequalSPEED_any | countryYear | 0 | 0, data=speed)))
(sumNobsContRob03c <- summary (NobsContRob03c <- felm (pbegSpeed2 ~ n50_d45_wequalSPEED_any | 0 | 0 | country, data=speed)))
(sumNobsContRob03d <- summary (NobsContRob03d <- felm (pbegSpeed2 ~ n50_d45_wequalSPEED_any | countryYear | 0 | country, data=speed)))

(sumNobsN800Rob03a <- summary (NobsN800Rob03a <- felm (pbegSpeed2 ~ n800_d45_wequalSPEED_any | 0 | 0 | 0, data=speed)))
(sumNobsN800Rob03b <- summary (NobsN800Rob03b <- felm (pbegSpeed2 ~ n800_d45_wequalSPEED_any | countryYear | 0 | 0, data=speed)))
(sumNobsN800Rob03c <- summary (NobsN800Rob03c <- felm (pbegSpeed2 ~ n800_d45_wequalSPEED_any | 0 | 0 | country, data=speed)))
(sumNobsN800Rob03d <- summary (NobsN800Rob03d <- felm (pbegSpeed2 ~ n800_d45_wequalSPEED_any | countryYear | 0 | country, data=speed)))

(sumNobsUNRegRob03a <- summary (NobsUNRegRob03a <- felm (pbegSpeed2 ~ nUN_d45_wequalSPEED_any | 0 | 0 | 0, data=speed)))
(sumNobsUNRegRob03b <- summary (NobsUNRegRob03b <- felm (pbegSpeed2 ~ nUN_d45_wequalSPEED_any | countryYear | 0 | 0, data=speed)))
(sumNobsUNRegRob03c <- summary (NobsUNRegRob03c <- felm (pbegSpeed2 ~ nUN_d45_wequalSPEED_any | 0 | 0 | country, data=speed)))
(sumNobsUNRegRob03d <- summary (NobsUNRegRob03d <- felm (pbegSpeed2 ~ nUN_d45_wequalSPEED_any | countryYear | 0 | country, data=speed)))

# getting the number of observations
(nobsContRob03 <- c (length (unique (speed[!is.na (speed$n50_d45_wequalSPEED_any),]$country))
                     , length (unique (NobsContRob03d$fe$countryYear))
                     , NobsContRob03d$N))
(nobsN800Rob03 <- c (length (unique (speed[!is.na (speed$n800_d45_wequalSPEED_any),]$country))
                     , length (unique (NobsN800Rob03d$fe$countryYear))
                     , NobsN800Rob03d$N))
(nobsUNRegRob03 <- c (length (unique (speed[!is.na (speed$nUN_d45_wequalSPEED_any),]$country))
                      , length (unique (NobsUNRegRob03d$fe$countryYear))
                      , NobsUNRegRob03d$N))

# doing the loop
v <- NULL
mContRob03 <- mN800Rob03 <- mUNRegRob03 <- list ()

system.time (
  for (v in 1:length (vContRob03)){
    
    ## defining the explanatory variable of interest
    speed$ivCont <- speed[,vContRob03[v]]
    speed$ivN800 <- speed[,vN800Rob03[v]]
    speed$ivUNReg <- speed[,vUNRegRob03[v]]
    
    ## (i) Contiguous neighbors
    
    # country-year FEs
    mContRob03[[v+0*length (vContRob03)]] <- summary (felm (pbegSpeed2 ~ ivCont | countryYear | 0 | country, data=speed))$coef
    mContRob03[[v+1*length (vContRob03)]] <- summary (felm (pbegSpeed2 ~ ivCont + ele30 | countryYear | 0 | country, data=speed))$coef
    
    
    ## (ii) 800km neighbors
    
    # country-year FEs
    mN800Rob03[[v+0*length (vN800Rob03)]] <- summary (felm (pbegSpeed2 ~ ivN800 | countryYear | 0 | country, data=speed))$coef
    mN800Rob03[[v+1*length (vN800Rob03)]] <- summary (felm (pbegSpeed2 ~ ivN800 + ele30 | countryYear | 0 | country, data=speed))$coef
    
    
    ## (iii) UN region neighbors
    
    # country-year FEs
    mUNRegRob03[[v+0*length (vUNRegRob03)]] <- summary (felm (pbegSpeed2 ~ ivUNReg | countryYear | 0 | country, data=speed))$coef
    mUNRegRob03[[v+1*length (vUNRegRob03)]] <- summary (felm (pbegSpeed2 ~ ivUNReg + ele30 | countryYear | 0 | country, data=speed))$coef
  }
) ## 98 seconds


## (3.2.10) Alternative protest measure (III): Mass Mobilization data (Clark and Regan)

# listing the explanatory variables
vContRob04 <- c ("n50_d45_wequalMMD_any", "n50_d90_wequalMMD_any", "n50_d120_wequalMMD_any"
                 , "n50_d45_wequalMMD_sum", "n50_d90_wequalMMD_sum", "n50_d120_wequalMMD_sum"
                 , "n50_d45_wSizeMMD_any", "n50_d90_wSizeMMD_any", "n50_d120_wSizeMMD_any")
vN800Rob04 <- c ("n800_d45_wequalMMD_any", "n800_d90_wequalMMD_any", "n800_d120_wequalMMD_any"
                 , "n800_d45_wequalMMD_sum", "n800_d90_wequalMMD_sum", "n800_d120_wequalMMD_sum"
                 , "n800_d45_wSizeMMD_any", "n800_d90_wSizeMMD_any", "n800_d120_wSizeMMD_any")
vUNRegRob04 <- c ("nUN_d45_wequalMMD_any", "nUN_d90_wequalMMD_any", "nUN_d120_wequalMMD_any"
                  , "nUN_d45_wequalMMD_sum", "nUN_d90_wequalMMD_sum", "nUN_d120_wequalMMD_sum"
                  , "nUN_d45_wSizeMMD_any", "nUN_d90_wSizeMMD_any", "nUN_d120_wSizeMMD_any")

# running one model to get the number of observations
(sumNobsContRob04a <- summary (NobsContRob04a <- felm (pbegMMD2 ~ n50_d45_wequalMMD_any | 0 | 0 | 0, data=mmd)))
(sumNobsContRob04b <- summary (NobsContRob04b <- felm (pbegMMD2 ~ n50_d45_wequalMMD_any | countryYear | 0 | 0, data=mmd)))
(sumNobsContRob04c <- summary (NobsContRob04c <- felm (pbegMMD2 ~ n50_d45_wequalMMD_any | 0 | 0 | country, data=mmd)))
(sumNobsContRob04d <- summary (NobsContRob04d <- felm (pbegMMD2 ~ n50_d45_wequalMMD_any | countryYear | 0 | country, data=mmd)))

(sumNobsN800Rob04a <- summary (NobsN800Rob04a <- felm (pbegMMD2 ~ n800_d45_wequalMMD_any | 0 | 0 | 0, data=mmd)))
(sumNobsN800Rob04b <- summary (NobsN800Rob04b <- felm (pbegMMD2 ~ n800_d45_wequalMMD_any | countryYear | 0 | 0, data=mmd)))
(sumNobsN800Rob04c <- summary (NobsN800Rob04c <- felm (pbegMMD2 ~ n800_d45_wequalMMD_any | 0 | 0 | country, data=mmd)))
(sumNobsN800Rob04d <- summary (NobsN800Rob04d <- felm (pbegMMD2 ~ n800_d45_wequalMMD_any | countryYear | 0 | country, data=mmd)))

(sumNobsUNRegRob04a <- summary (NobsUNRegRob04a <- felm (pbegMMD2 ~ nUN_d45_wequalMMD_any | 0 | 0 | 0, data=mmd)))
(sumNobsUNRegRob04b <- summary (NobsUNRegRob04b <- felm (pbegMMD2 ~ nUN_d45_wequalMMD_any | countryYear | 0 | 0, data=mmd)))
(sumNobsUNRegRob04c <- summary (NobsUNRegRob04c <- felm (pbegMMD2 ~ nUN_d45_wequalMMD_any | 0 | 0 | country, data=mmd)))
(sumNobsUNRegRob04d <- summary (NobsUNRegRob04d <- felm (pbegMMD2 ~ nUN_d45_wequalMMD_any | countryYear | 0 | country, data=mmd)))

# getting the number of observations
(nobsContRob04 <- c (length (unique (mmd[!is.na (mmd$n50_d45_wequalMMD_any),]$country))
                     , length (unique (NobsContRob04d$fe$countryYear))
                     , NobsContRob04d$N))
(nobsN800Rob04 <- c (length (unique (mmd[!is.na (mmd$n800_d45_wequalMMD_any),]$country))
                     , length (unique (NobsN800Rob04d$fe$countryYear))
                     , NobsN800Rob04d$N))
(nobsUNRegRob04 <- c (length (unique (mmd[!is.na (mmd$nUN_d45_wequalMMD_any),]$country))
                      , length (unique (NobsUNRegRob04d$fe$countryYear))
                      , NobsUNRegRob04d$N))

# doing the loop
v <- NULL
mContRob04 <- mN800Rob04 <- mUNRegRob04 <- list ()

system.time (
  for (v in 1:length (vContRob04)){
    
    ## defining the explanatory variable of interest
    mmd$ivCont <- mmd[,vContRob04[v]]
    mmd$ivN800 <- mmd[,vN800Rob04[v]]
    mmd$ivUNReg <- mmd[,vUNRegRob04[v]]
    
    ## (i) Contiguous neighbors
    
    # country-year FEs
    mContRob04[[v+0*length (vContRob04)]] <- summary (felm (pbegMMD2 ~ ivCont | countryYear | 0 | country, data=mmd))$coef
    mContRob04[[v+1*length (vContRob04)]] <- summary (felm (pbegMMD2 ~ ivCont + ele30 | countryYear | 0 | country, data=mmd))$coef
    
    
    ## (ii) 800km neighbors
    
    # country-year FEs
    mN800Rob04[[v+0*length (vN800Rob04)]] <- summary (felm (pbegMMD2 ~ ivN800 | countryYear | 0 | country, data=mmd))$coef
    mN800Rob04[[v+1*length (vN800Rob04)]] <- summary (felm (pbegMMD2 ~ ivN800 + ele30 | countryYear | 0 | country, data=mmd))$coef
    
    
    ## (iii) UN region neighbors
    
    # country-year FEs
    mUNRegRob04[[v+0*length (vUNRegRob04)]] <- summary (felm (pbegMMD2 ~ ivUNReg | countryYear | 0 | country, data=mmd))$coef
    mUNRegRob04[[v+1*length (vUNRegRob04)]] <- summary (felm (pbegMMD2 ~ ivUNReg + ele30 | countryYear | 0 | country, data=mmd))$coef
  }
) ## 192 seconds


## (3.2.11) Subsamples (I): 1989, Diffusion or commonalities?

# weeks since Gorbachev's speech
(sum.cont89d45a <- summary (cont89d45a <- felm (pbega2 ~ n50_d45_wequal_any + daysSpeech2*eeurope | 0 | 0 | 0, data=base89)))
(sum.cont89d90a <- summary (cont89d90a <- felm (pbega2 ~ n50_d90_wequal_any + daysSpeech2*eeurope | 0 | 0 | 0, data=base89)))
(sum.cont89d120a <- summary (cont89d120a <- felm (pbega2 ~ n50_d120_wequal_any + daysSpeech2*eeurope | 0 | 0 | 0, data=base89)))

(sum.n80089d45a <- summary (n80089d45a <- felm (pbega2 ~ n800_d45_wequal_any + daysSpeech2*eeurope | 0 | 0 | 0, data=base89)))
(sum.n80089d90a <- summary (n80089d90a <- felm (pbega2 ~ n800_d90_wequal_any + daysSpeech2*eeurope | 0 | 0 | 0, data=base89)))
(sum.n80089d120a <- summary (n80089d120a <- felm (pbega2 ~ n800_d120_wequal_any + daysSpeech2*eeurope | 0 | 0 | 0, data=base89)))

(sum.unreg89d45a <- summary (unreg89d45a <- felm (pbega2 ~ nUN_d45_wequal_any + daysSpeech2*eeurope | 0 | 0 | 0, data=base89)))
(sum.unreg89d90a <- summary (unreg89d90a <- felm (pbega2 ~ nUN_d90_wequal_any + daysSpeech2*eeurope | 0 | 0 | 0, data=base89)))
(sum.unreg89d120a <- summary (unreg89d120a <- felm (pbega2 ~ nUN_d120_wequal_any + daysSpeech2*eeurope | 0 | 0 | 0, data=base89)))

# dummies for 45, 90 or 120 days after speech
(sum.cont89d45b <- summary (cont89d45b <- felm (pbega2 ~ n50_d45_wequal_any + speech45*eeurope | 0 | 0 | 0, data=base89)))
(sum.cont89d90b <- summary (cont89d90b <- felm (pbega2 ~ n50_d90_wequal_any + speech90*eeurope | 0 | 0 | 0, data=base89)))
(sum.cont89d120b <- summary (cont89d120b <- felm (pbega2 ~ n50_d120_wequal_any + speech120*eeurope | 0 | 0 | 0, data=base89)))

(sum.n80089d45b <- summary (n80089d45b <- felm (pbega2 ~ n800_d45_wequal_any + speech45*eeurope | 0 | 0 | 0, data=base89)))
(sum.n80089d90b <- summary (n80089d90b <- felm (pbega2 ~ n800_d90_wequal_any + speech90*eeurope | 0 | 0 | 0, data=base89)))
(sum.n80089d120b <- summary (n80089d120b <- felm (pbega2 ~ n800_d120_wequal_any + speech120*eeurope | 0 | 0 | 0, data=base89)))

(sum.unreg89d45b <- summary (unreg89d45b <- felm (pbega2 ~ nUN_d45_wequal_any + speech45*eeurope | 0 | 0 | 0, data=base89)))
(sum.unreg89d90b <- summary (unreg89d90b <- felm (pbega2 ~ nUN_d90_wequal_any + speech90*eeurope | 0 | 0 | 0, data=base89)))
(sum.unreg89d120b <- summary (unreg89d120b <- felm (pbega2 ~ nUN_d120_wequal_any + speech120*eeurope | 0 | 0 | 0, data=base89)))


## (3.2.12) Subsamples (II): Arab Spring

# listing the explanatory variables
vRob15d30 <- c ("n50_d30_wequal_any", "n50_d30_wequal_sum", "n50_d30_wSize_any"
                , "n800_d30_wequal_any", "n800_d30_wequal_sum", "n800_d30_wSize_any"
                , "nUN_d30_wequal_any", "nUN_d30_wequal_sum", "nUN_d30_wSize_any")
vRob15d45 <- c ("n50_d45_wequal_any", "n50_d45_wequal_sum", "n50_d45_wSize_any"
                , "n800_d45_wequal_any", "n800_d45_wequal_sum", "n800_d45_wSize_any"
                , "nUN_d45_wequal_any", "nUN_d45_wequal_sum", "nUN_d45_wSize_any")
vRob15d90 <- c ("n50_d90_wequal_any", "n50_d90_wequal_sum", "n50_d90_wSize_any"
                , "n800_d90_wequal_any", "n800_d90_wequal_sum", "n800_d90_wSize_any"
                , "nUN_d90_wequal_any", "nUN_d90_wequal_sum", "nUN_d90_wSize_any")
vRob15d120 <- c ("n50_d120_wequal_any", "n50_d120_wequal_sum", "n50_d120_wSize_any"
                 , "n800_d120_wequal_any", "n800_d120_wequal_sum", "n800_d120_wSize_any"
                 , "nUN_d120_wequal_any", "nUN_d120_wequal_sum", "nUN_d120_wSize_any")

# running one model to get the number of observations
(sumNbase11Cont01a <- summary (Nbase11Cont01a <- felm (pbega2 ~ n50_d45_wequal_any | country | 0 | country, data=base11)))
(sumNbspringCont01a <- summary (NbspringCont01a <- felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=bspring)))
(sumNbspring11Cont01a <- summary (Nbspring11Cont01a <- felm (pbega2 ~ n50_d45_wequal_any | country | 0 | country, data=bspring11)))
(sumNbmenaCont01a <- summary (NbmenaCont01a <- felm (pbega2 ~ n50_d45_wequal_any | countryYear | 0 | country, data=bmena)))
(sumNbmena11Cont01a <- summary (Nbmena11Cont01a <- felm (pbega2 ~ n50_d45_wequal_any | country | 0 | country, data=bmena11)))

(sumNbase11N80001a <- summary (Nbase11N80001a <- felm (pbega2 ~ n800_d45_wequal_any | country | 0 | country, data=base11)))
(sumNbspringN80001a <- summary (NbspringN80001a <- felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=bspring)))
(sumNbspring11N80001a <- summary (Nbspring11N80001a <- felm (pbega2 ~ n800_d45_wequal_any | country | 0 | country, data=bspring11)))
(sumNbmenaN80001a <- summary (NbmenaN80001a <- felm (pbega2 ~ n800_d45_wequal_any | countryYear | 0 | country, data=bmena)))
(sumNbmena11N80001a <- summary (Nbmena11N80001a <- felm (pbega2 ~ n800_d45_wequal_any | country | 0 | country, data=bmena11)))

(sumNbase11UNReg01a <- summary (Nbase11UNReg01a <- felm (pbega2 ~ nUN_d45_wequal_any | country | 0 | country, data=base11)))
(sumNbspringUNReg01a <- summary (NbspringUNReg01a <- felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=bspring)))
(sumNbspring11UNReg01a <- summary (Nbspring11UNReg01a <- felm (pbega2 ~ nUN_d45_wequal_any | country | 0 | country, data=bspring11)))
(sumNbmenaUNReg01a <- summary (NbmenaUNReg01a <- felm (pbega2 ~ nUN_d45_wequal_any | countryYear | 0 | country, data=bmena)))
(sumNbmena11UNReg01a <- summary (Nbmena11UNReg01a <- felm (pbega2 ~ nUN_d45_wequal_any | country | 0 | country, data=bmena11)))

# getting the number of observations
(nbase11Cont01main <- c (length (unique (base11[!is.na (base11$n50_d45_wequal_any),]$country))
                         , length (unique (Nbase11Cont01a$fe$country))
                         , Nbase11Cont01a$N))
(nbspringCont01main <- c (length (unique (bspring[!is.na (bspring$n50_d45_wequal_any),]$country))
                          , length (unique (NbspringCont01a$fe$country))
                          , NbspringCont01a$N))
(nbspring11Cont01main <- c (length (unique (bspring11[!is.na (bspring11$n50_d45_wequal_any),]$country))
                            , length (unique (Nbspring11Cont01a$fe$country))
                            , Nbspring11Cont01a$N))
(nbmenaCont01main <- c (length (unique (bmena[!is.na (bmena$n50_d45_wequal_any),]$country))
                        , length (unique (NbmenaCont01a$fe$country))
                        , NbmenaCont01a$N))
(nbmena11Cont01main <- c (length (unique (bmena11[!is.na (bmena11$n50_d45_wequal_any),]$country))
                          , length (unique (Nbmena11Cont01a$fe$country))
                          , Nbmena11Cont01a$N))

(nbase11N80001main <- c (length (unique (base11[!is.na (base11$n800_d45_wequal_any),]$country))
                         , length (unique (Nbase11N80001a$fe$country))
                         , Nbase11N80001a$N))
(nbspringN80001main <- c (length (unique (bspring[!is.na (bspring$n800_d45_wequal_any),]$country))
                          , length (unique (NbspringN80001a$fe$country))
                          , NbspringN80001a$N))
(nbspring11N80001main <- c (length (unique (bspring11[!is.na (bspring11$n800_d45_wequal_any),]$country))
                            , length (unique (Nbspring11N80001a$fe$country))
                            , Nbspring11N80001a$N))
(nbmenaN80001main <- c (length (unique (bmena[!is.na (bmena$n800_d45_wequal_any),]$country))
                        , length (unique (NbmenaN80001a$fe$country))
                        , NbmenaN80001a$N))
(nbmena11N80001main <- c (length (unique (bmena11[!is.na (bmena11$n800_d45_wequal_any),]$country))
                          , length (unique (Nbmena11N80001a$fe$country))
                          , Nbmena11N80001a$N))

(nbase11UNReg01main <- c (length (unique (base11[!is.na (base11$nUN_d45_wequal_any),]$country))
                          , length (unique (Nbase11UNReg01a$fe$country))
                          , Nbase11UNReg01a$N))
(nbspringUNReg01main <- c (length (unique (bspring[!is.na (bspring$nUN_d45_wequal_any),]$country))
                           , length (unique (NbspringUNReg01a$fe$country))
                           , NbspringUNReg01a$N))
(nbspring11UNReg01main <- c (length (unique (bspring11[!is.na (bspring11$nUN_d45_wequal_any),]$country))
                             , length (unique (Nbspring11UNReg01a$fe$country))
                             , Nbspring11UNReg01a$N))
(nbmenaUNReg01main <- c (length (unique (bmena[!is.na (bmena$nUN_d45_wequal_any),]$country))
                         , length (unique (NbmenaUNReg01a$fe$country))
                         , NbmenaUNReg01a$N))
(nbmena11UNReg01main <- c (length (unique (bmena11[!is.na (bmena11$nUN_d45_wequal_any),]$country))
                           , length (unique (Nbmena11UNReg01a$fe$country))
                           , Nbmena11UNReg01a$N))

# running the models
v <- NULL
mRob15d30 <- mRob15d45 <- mRob15d90 <- mRob15d120 <- list () ## we'll put the models here

system.time (
  for (v in 1:length (vRob15d45)){
    
    ## defining the explanatory variable of interest
    base11$iv30 <- base11[,vRob15d30[v]]
    base11$iv45 <- base11[,vRob15d45[v]]
    base11$iv90 <- base11[,vRob15d90[v]]
    base11$iv120 <- base11[,vRob15d120[v]]
    
    bspring$iv30 <- bspring[,vRob15d30[v]]
    bspring$iv45 <- bspring[,vRob15d45[v]]
    bspring$iv90 <- bspring[,vRob15d90[v]]
    bspring$iv120 <- bspring[,vRob15d120[v]]
    
    bspring11$iv30 <- bspring11[,vRob15d30[v]]
    bspring11$iv45 <- bspring11[,vRob15d45[v]]
    bspring11$iv90 <- bspring11[,vRob15d90[v]]
    bspring11$iv120 <- bspring11[,vRob15d120[v]]
    
    bmena$iv30 <- bmena[,vRob15d30[v]]
    bmena$iv45 <- bmena[,vRob15d45[v]]
    bmena$iv90 <- bmena[,vRob15d90[v]]
    bmena$iv120 <- bmena[,vRob15d120[v]]
    
    bmena11$iv30 <- bmena11[,vRob15d30[v]]
    bmena11$iv45 <- bmena11[,vRob15d45[v]]
    bmena11$iv90 <- bmena11[,vRob15d90[v]]
    bmena11$iv120 <- bmena11[,vRob15d120[v]]
    
    
    ## (i) 30-day time frame
    
    # Main sample, 2011 only: no FEs but SEs clustered by COUNTRY
    mRob15d30[[v+0*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 | 0 | 0 | country, data=base11))$coef
    mRob15d30[[v+1*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | 0 | 0 | country, data=base11))$coef
    
    # Main sample, 2011 only: FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d30[[v+2*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 | country | 0 | country, data=base11))$coef
    mRob15d30[[v+3*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | country | 0 | country, data=base11))$coef
    
    # Arab Spring sample: FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob15d30[[v+4*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 | countryYear | 0 | country, data=bspring))$coef
    mRob15d30[[v+5*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | countryYear | 0 | country, data=bspring))$coef
    
    # Arab Spring sample, 2011 only; no FEs but SEs clustered by COUNTRY
    mRob15d30[[v+6*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 | 0 | 0 | country, data=bspring11))$coef
    mRob15d30[[v+7*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | 0 | 0 | country, data=bspring11))$coef
    
    # Arab Spring sample, 2011 only; FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d30[[v+8*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 | country | 0 | country, data=bspring11))$coef
    mRob15d30[[v+9*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | country | 0 | country, data=bspring11))$coef
    
    # MENA sample: no FEs but SEs clustered by COUNTRY
    mRob15d30[[v+10*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 | 0 | 0 | country, data=bmena))$coef
    mRob15d30[[v+11*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | 0 | 0 | country, data=bmena))$coef
    
    # MENA sample: FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d30[[v+12*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 | country | 0 | country, data=bmena))$coef
    mRob15d30[[v+13*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | country | 0 | country, data=bmena))$coef
    
    # MENA sample: FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob15d30[[v+14*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 | countryYear | 0 | country, data=bmena))$coef
    mRob15d30[[v+15*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | countryYear | 0 | country, data=bmena))$coef
    
    # MENA sample, 2011 only; no FEs but SEs clustered by COUNTRY
    mRob15d30[[v+16*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 | 0 | 0 | country, data=bmena11))$coef
    mRob15d30[[v+17*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | 0 | 0 | country, data=bmena11))$coef
    
    # MENA sample, 2011 only; FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d30[[v+18*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 | country | 0 | country, data=bmena11))$coef
    mRob15d30[[v+19*length (vRob15d30)]] <- summary (felm (pbega2 ~ iv30 + ele30 | country | 0 | country, data=bmena11))$coef
    
    
    ## (ii) 45-day time frame
    
    # Main sample, 2011 only: no FEs but SEs clustered by COUNTRY
    mRob15d45[[v+0*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 | 0 | 0 | country, data=base11))$coef
    mRob15d45[[v+1*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | 0 | 0 | country, data=base11))$coef
    
    # Main sample, 2011 only: FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d45[[v+2*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 | country | 0 | country, data=base11))$coef
    mRob15d45[[v+3*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | country | 0 | country, data=base11))$coef
    
    # Arab Spring sample: FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob15d45[[v+4*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 | countryYear | 0 | country, data=bspring))$coef
    mRob15d45[[v+5*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | countryYear | 0 | country, data=bspring))$coef
    
    # Arab Spring sample, 2011 only; no FEs but SEs clustered by COUNTRY
    mRob15d45[[v+6*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 | 0 | 0 | country, data=bspring11))$coef
    mRob15d45[[v+7*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | 0 | 0 | country, data=bspring11))$coef
    
    # Arab Spring sample, 2011 only; FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d45[[v+8*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 | country | 0 | country, data=bspring11))$coef
    mRob15d45[[v+9*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | country | 0 | country, data=bspring11))$coef
    
    # MENA sample: no FEs but SEs clustered by COUNTRY
    mRob15d45[[v+10*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 | 0 | 0 | country, data=bmena))$coef
    mRob15d45[[v+11*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | 0 | 0 | country, data=bmena))$coef
    
    # MENA sample: FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d45[[v+12*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 | country | 0 | country, data=bmena))$coef
    mRob15d45[[v+13*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | country | 0 | country, data=bmena))$coef
    
    # MENA sample: FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob15d45[[v+14*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 | countryYear | 0 | country, data=bmena))$coef
    mRob15d45[[v+15*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | countryYear | 0 | country, data=bmena))$coef
    
    # MENA sample, 2011 only; no FEs but SEs clustered by COUNTRY
    mRob15d45[[v+16*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 | 0 | 0 | country, data=bmena11))$coef
    mRob15d45[[v+17*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | 0 | 0 | country, data=bmena11))$coef
    
    # MENA sample, 2011 only; FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d45[[v+18*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 | country | 0 | country, data=bmena11))$coef
    mRob15d45[[v+19*length (vRob15d45)]] <- summary (felm (pbega2 ~ iv45 + ele45 | country | 0 | country, data=bmena11))$coef
    
    
    ## (iii) 90-day time frame
    
    # Main sample, 2011 only: no FEs but SEs clustered by COUNTRY
    mRob15d90[[v+0*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 | 0 | 0 | country, data=base11))$coef
    mRob15d90[[v+1*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | 0 | 0 | country, data=base11))$coef
    
    # Main sample, 2011 only: FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d90[[v+2*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 | country | 0 | country, data=base11))$coef
    mRob15d90[[v+3*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | country | 0 | country, data=base11))$coef
    
    # Arab Spring sample: FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob15d90[[v+4*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 | countryYear | 0 | country, data=bspring))$coef
    mRob15d90[[v+5*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | countryYear | 0 | country, data=bspring))$coef
    
    # Arab Spring sample, 2011 only; no FEs but SEs clustered by COUNTRY
    mRob15d90[[v+6*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 | 0 | 0 | country, data=bspring11))$coef
    mRob15d90[[v+7*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | 0 | 0 | country, data=bspring11))$coef
    
    # Arab Spring sample, 2011 only; FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d90[[v+8*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 | country | 0 | country, data=bspring11))$coef
    mRob15d90[[v+9*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | country | 0 | country, data=bspring11))$coef
    
    # MENA sample: no FEs but SEs clustered by COUNTRY
    mRob15d90[[v+10*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 | 0 | 0 | country, data=bmena))$coef
    mRob15d90[[v+11*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | 0 | 0 | country, data=bmena))$coef
    
    # MENA sample: FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d90[[v+12*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 | country | 0 | country, data=bmena))$coef
    mRob15d90[[v+13*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | country | 0 | country, data=bmena))$coef
    
    # MENA sample: FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob15d90[[v+14*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 | countryYear | 0 | country, data=bmena))$coef
    mRob15d90[[v+15*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | countryYear | 0 | country, data=bmena))$coef
    
    # MENA sample, 2011 only; no FEs but SEs clustered by COUNTRY
    mRob15d90[[v+16*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 | 0 | 0 | country, data=bmena11))$coef
    mRob15d90[[v+17*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | 0 | 0 | country, data=bmena11))$coef
    
    # MENA sample, 2011 only; FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d90[[v+18*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 | country | 0 | country, data=bmena11))$coef
    mRob15d90[[v+19*length (vRob15d90)]] <- summary (felm (pbega2 ~ iv90 + ele90 | country | 0 | country, data=bmena11))$coef
    
    
    ## (iv) 120-day time frame
    
    # Main sample, 2011 only: no FEs but SEs clustered by COUNTRY
    mRob15d120[[v+0*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 | 0 | 0 | country, data=base11))$coef
    mRob15d120[[v+1*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | 0 | 0 | country, data=base11))$coef
    
    # Main sample, 2011 only: FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d120[[v+2*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 | country | 0 | country, data=base11))$coef
    mRob15d120[[v+3*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | country | 0 | country, data=base11))$coef
    
    # Arab Spring sample: FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob15d120[[v+4*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 | countryYear | 0 | country, data=bspring))$coef
    mRob15d120[[v+5*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | countryYear | 0 | country, data=bspring))$coef
    
    # Arab Spring sample, 2011 only; no FEs but SEs clustered by COUNTRY
    mRob15d120[[v+6*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 | 0 | 0 | country, data=bspring11))$coef
    mRob15d120[[v+7*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | 0 | 0 | country, data=bspring11))$coef
    
    # Arab Spring sample, 2011 only; FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d120[[v+8*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 | country | 0 | country, data=bspring11))$coef
    mRob15d120[[v+9*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | country | 0 | country, data=bspring11))$coef
    
    # MENA sample: no FEs but SEs clustered by COUNTRY
    mRob15d120[[v+10*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 | 0 | 0 | country, data=bmena))$coef
    mRob15d120[[v+11*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | 0 | 0 | country, data=bmena))$coef
    
    # MENA sample: FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d120[[v+12*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 | country | 0 | country, data=bmena))$coef
    mRob15d120[[v+13*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | country | 0 | country, data=bmena))$coef
    
    # MENA sample: FEs by COUNTRY-YEAR and SEs clustered by COUNTRY
    mRob15d120[[v+14*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 | countryYear | 0 | country, data=bmena))$coef
    mRob15d120[[v+15*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | countryYear | 0 | country, data=bmena))$coef
    
    # MENA sample, 2011 only; no FEs but SEs clustered by COUNTRY
    mRob15d120[[v+16*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 | 0 | 0 | country, data=bmena11))$coef
    mRob15d120[[v+17*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | 0 | 0 | country, data=bmena11))$coef
    
    # MENA sample, 2011 only; FEs by COUNTRY and SEs clustered by COUNTRY
    mRob15d120[[v+18*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 | country | 0 | country, data=bmena11))$coef
    mRob15d120[[v+19*length (vRob15d120)]] <- summary (felm (pbega2 ~ iv120 + ele120 | country | 0 | country, data=bmena11))$coef
  }
) ## 596 seconds


## (3.2.13) Robustness: Conditional logit models

# listing the explanatory variables
vContRob06 <- c ("n50_d45_wequal_any", "n50_d90_wequal_any", "n50_d120_wequal_any"
                 , "n50_d45_wequal_sum", "n50_d90_wequal_sum", "n50_d120_wequal_sum")
vN800Rob06 <- c ("n800_d45_wequal_any", "n800_d90_wequal_any", "n800_d120_wequal_any"
                 , "n800_d45_wequal_sum", "n800_d90_wequal_sum", "n800_d120_wequal_sum")
vUNRegRob06 <- c ("nUN_d45_wequal_any", "nUN_d90_wequal_any", "nUN_d120_wequal_any"
                  , "nUN_d45_wequal_sum", "nUN_d90_wequal_sum", "nUN_d120_wequal_sum")

# running one model to get the number of observations
(sumNobsContRob06d <- summary (NobsContRob06d <- clogit (pbega ~ n50_d45_wequal_any + strata (countryYear), data=base)))
(sumNobsN800Rob06d <- summary (NobsN800Rob06d <- clogit (pbega ~ n800_d45_wequal_any + strata (countryYear), data=base)))
(sumNobsUNRegRob06d <- summary (NobsUNRegRob06d <- clogit (pbega ~ nUN_d45_wequal_any + strata (countryYear), data=base)))

# getting the number of observations
(nobsContRob06 <- c (length (unique (base[!is.na (base$n50_d45_wequal_any),]$country))
                     , length (NobsContRob06d$xlevels$strata)
                     , NobsContRob06d$n))
(nobsN800Rob06 <- c (length (unique (base[!is.na (base$n800_d45_wequal_any),]$country))
                     , length (NobsN800Rob06d$xlevels$strata)
                     , NobsN800Rob06d$n))
(nobsUNRegRob06 <- c (length (unique (base[!is.na (base$nUN_d45_wequal_any),]$country))
                      , length (NobsUNRegRob06d$xlevels$strata)
                      , NobsUNRegRob06d$n))

# doing the loop
v <- NULL
mContRob06 <- mN800Rob06 <- mUNRegRob06 <- list ()

system.time (
  for (v in 1:length (vContRob06)){
    
    ## defining the explanatory variable of interest
    base$ivCont <- base[,vContRob06[v]]
    base$ivN800 <- base[,vN800Rob06[v]]
    base$ivUNReg <- base[,vUNRegRob06[v]]
    
    ## (i) Contiguous neighbors
    
    # country-year FEs
    mContRob06[[v+0*length (vContRob06)]] <- summary (clogit (pbega ~ ivCont + strata (countryYear), data=base))$coef
    mContRob06[[v+1*length (vContRob06)]] <- summary (clogit (pbega ~ ivCont + ele30 + strata (countryYear), data=base))$coef
    mContRob06[[v+2*length (vContRob06)]] <- summary (clogit (pbega ~ ivCont + I(ivCont*ele30) + ele30 + strata (countryYear), data=base))$coef
    
    
    ## (ii) 800km neighbors
    
    # country-year FEs
    mN800Rob06[[v+0*length (vN800Rob06)]] <- summary (clogit (pbega ~ ivN800 + strata (countryYear), data=base))$coef
    mN800Rob06[[v+1*length (vN800Rob06)]] <- summary (clogit (pbega ~ ivN800 + ele30 + strata (countryYear), data=base))$coef
    mN800Rob06[[v+2*length (vN800Rob06)]] <- summary (clogit (pbega ~ ivN800 + I(ivN800*ele30) + ele30 + strata (countryYear), data=base))$coef
    
    
    ## (iii) UN region neighbors
    
    # country-year FEs
    mUNRegRob06[[v+0*length (vUNRegRob06)]] <- summary (clogit (pbega ~ ivUNReg + strata (countryYear), data=base))$coef
    mUNRegRob06[[v+1*length (vUNRegRob06)]] <- summary (clogit (pbega ~ ivUNReg + ele30 + strata (countryYear), data=base))$coef
    mUNRegRob06[[v+2*length (vUNRegRob06)]] <- summary (clogit (pbega ~ ivUNReg + I(ivUNReg*ele30) + ele30 + strata (countryYear), data=base))$coef
  }
)   ## 8768 seconds


## (3.2.14) Robustness: Interactions between protests and elections (Tables A61-A62)

# listing the explanatory variables
vContRob05 <- c ("n50_d45_wElec_any", "n50_d90_wElec_any", "n50_d120_wElec_any")
vN800Rob05 <- c ("n800_d45_wElec_any", "n800_d90_wElec_any", "n800_d120_wElec_any")
vUNRegRob05 <- c ("nUN_d45_wElec_any", "nUN_d90_wElec_any", "nUN_d120_wElec_any")

# running one model to get the number of observations
(sumNobsContRob05a <- summary (NobsContRob05a <- felm (pbega2 ~ n50_d45_wElec_any | 0 | 0 | 0, data=base)))
(sumNobsContRob05b <- summary (NobsContRob05b <- felm (pbega2 ~ n50_d45_wElec_any | countryYear | 0 | 0, data=base)))
(sumNobsContRob05c <- summary (NobsContRob05c <- felm (pbega2 ~ n50_d45_wElec_any | 0 | 0 | country, data=base)))
(sumNobsContRob05d <- summary (NobsContRob05d <- felm (pbega2 ~ n50_d45_wElec_any | countryYear | 0 | country, data=base)))

(sumNobsN800Rob05a <- summary (NobsN800Rob05a <- felm (pbega2 ~ n800_d45_wElec_any | 0 | 0 | 0, data=base)))
(sumNobsN800Rob05b <- summary (NobsN800Rob05b <- felm (pbega2 ~ n800_d45_wElec_any | countryYear | 0 | 0, data=base)))
(sumNobsN800Rob05c <- summary (NobsN800Rob05c <- felm (pbega2 ~ n800_d45_wElec_any | 0 | 0 | country, data=base)))
(sumNobsN800Rob05d <- summary (NobsN800Rob05d <- felm (pbega2 ~ n800_d45_wElec_any | countryYear | 0 | country, data=base)))

(sumNobsUNRegRob05a <- summary (NobsUNRegRob05a <- felm (pbega2 ~ nUN_d45_wElec_any | 0 | 0 | 0, data=base)))
(sumNobsUNRegRob05b <- summary (NobsUNRegRob05b <- felm (pbega2 ~ nUN_d45_wElec_any | countryYear | 0 | 0, data=base)))
(sumNobsUNRegRob05c <- summary (NobsUNRegRob05c <- felm (pbega2 ~ nUN_d45_wElec_any | 0 | 0 | country, data=base)))
(sumNobsUNRegRob05d <- summary (NobsUNRegRob05d <- felm (pbega2 ~ nUN_d45_wElec_any | countryYear | 0 | country, data=base)))

# getting the number of observations
(nobsContRob05 <- c (length (unique (base$country))
                     , length (unique (NobsContRob05d$fe$countryYear))
                     , NobsContRob05d$N))
(nobsN800Rob05 <- c (length (unique (base$country))
                     , length (unique (NobsN800Rob05d$fe$countryYear))
                     , NobsN800Rob05d$N))
(nobsUNRegRob05 <- c (length (unique (base$country))
                      , length (unique (NobsUNRegRob05d$fe$countryYear))
                      , NobsUNRegRob05d$N))

# doing the loop
v <- NULL
mContRob05 <- mN800Rob05 <- mUNRegRob05 <- list ()

system.time (
  for (v in 1:length (vContRob05)){
    
    ## defining the explanatory variable of interest
    base$ivCont <- base[,vContRob05[v]]
    base$ivN800 <- base[,vN800Rob05[v]]
    base$ivUNReg <- base[,vUNRegRob05[v]]
    
    ## (i) Contiguous neighbors
    
    # country-year FEs
    mContRob05[[v+0*length (vContRob05)]] <- summary (felm (pbega2 ~ ivCont | countryYear | 0 | country, data=base))$coef
    mContRob05[[v+1*length (vContRob05)]] <- summary (felm (pbega2 ~ ivCont + ele30 | countryYear | 0 | country, data=base))$coef
    mContRob05[[v+2*length (vContRob05)]] <- summary (felm (pbega2 ~ ivCont + I(ivCont*ele30) + ele30 | countryYear | 0 | country, data=base))$coef
    
    
    ## (ii) 800km neighbors
    
    # country-year FEs
    mN800Rob05[[v+0*length (vN800Rob05)]] <- summary (felm (pbega2 ~ ivN800 | countryYear | 0 | country, data=base))$coef
    mN800Rob05[[v+1*length (vN800Rob05)]] <- summary (felm (pbega2 ~ ivN800 + ele30 | countryYear | 0 | country, data=base))$coef
    mN800Rob05[[v+2*length (vN800Rob05)]] <- summary (felm (pbega2 ~ ivN800 + I(ivN800*ele30) + ele30 | countryYear | 0 | country, data=base))$coef
    
    
    ## (iii) UN region neighbors
    
    # country-year FEs
    mUNRegRob05[[v+0*length (vUNRegRob05)]] <- summary (felm (pbega2 ~ ivUNReg | countryYear | 0 | country, data=base))$coef
    mUNRegRob05[[v+1*length (vUNRegRob05)]] <- summary (felm (pbega2 ~ ivUNReg + ele30 | countryYear | 0 | country, data=base))$coef
    mUNRegRob05[[v+2*length (vUNRegRob05)]] <- summary (felm (pbega2 ~ ivUNReg + I(ivUNReg*ele30) + ele30 | countryYear | 0 | country, data=base))$coef
  }
) ## 112 seconds


## (3.2.15) Bunce results (I): Electoral protest in last election in neighboring country

# listing the explanatory variables
vContRob07 <- c ("n50_dEle_near_any", "n50_dEle_near_sum", "n50_dEle_Sizenear_any"
                 , "n50_dEle_wSucnear2_any2", "n50_dEle_wReprnear2_any2")
vN800Rob07 <- c ("n800_dEle_near_any", "n800_dEle_near_sum", "n800_dEle_Sizenear_any"
                 , "n800_dEle_wSucnear2_any2", "n800_dEle_wReprnear2_any2")
vUNRegRob07 <- c ("nUN_dEle_near_any", "nUN_dEle_near_sum", "nUN_dEle_Sizenear_any"
                  , "nUN_dEle_wSucnear2_any2", "nUN_dEle_wReprnear2_any2")

# running one model to get the number of observations
(sumNobsContRob07a <- summary (NobsContRob07a <- felm (pbega2 ~ n50_dEle_near_any | 0 | 0 | 0, data=base)))
(sumNobsContRob07b <- summary (NobsContRob07b <- felm (pbega2 ~ n50_dEle_near_any | countryYear | 0 | 0, data=base)))
(sumNobsContRob07c <- summary (NobsContRob07c <- felm (pbega2 ~ n50_dEle_near_any | 0 | 0 | country, data=base)))
(sumNobsContRob07d <- summary (NobsContRob07d <- felm (pbega2 ~ n50_dEle_near_any | countryYear | 0 | country, data=base)))

(sumNobsN800Rob07a <- summary (NobsN800Rob07a <- felm (pbega2 ~ n800_dEle_near_any | 0 | 0 | 0, data=base)))
(sumNobsN800Rob07b <- summary (NobsN800Rob07b <- felm (pbega2 ~ n800_dEle_near_any | countryYear | 0 | 0, data=base)))
(sumNobsN800Rob07c <- summary (NobsN800Rob07c <- felm (pbega2 ~ n800_dEle_near_any | 0 | 0 | country, data=base)))
(sumNobsN800Rob07d <- summary (NobsN800Rob07d <- felm (pbega2 ~ n800_dEle_near_any | countryYear | 0 | country, data=base)))

(sumNobsUNRegRob07a <- summary (NobsUNRegRob07a <- felm (pbega2 ~ nUN_dEle_near_any | 0 | 0 | 0, data=base)))
(sumNobsUNRegRob07b <- summary (NobsUNRegRob07b <- felm (pbega2 ~ nUN_dEle_near_any | countryYear | 0 | 0, data=base)))
(sumNobsUNRegRob07c <- summary (NobsUNRegRob07c <- felm (pbega2 ~ nUN_dEle_near_any | 0 | 0 | country, data=base)))
(sumNobsUNRegRob07d <- summary (NobsUNRegRob07d <- felm (pbega2 ~ nUN_dEle_near_any | countryYear | 0 | country, data=base)))

# getting the number of observations
(nobsContRob07 <- c (length (unique (base[!is.na (base$n50_dEle_near_any),]$country))
                     , length (unique (NobsContRob07d$fe$countryYear))
                     , NobsContRob07d$N))
(nobsN800Rob07 <- c (length (unique (base[!is.na (base$n800_dEle_near_any),]$country))
                     , length (unique (NobsN800Rob07d$fe$countryYear))
                     , NobsN800Rob07d$N))
(nobsUNRegRob07 <- c (length (unique (base[!is.na (base$nUN_dEle_near_any),]$country))
                      , length (unique (NobsUNRegRob07d$fe$countryYear))
                      , NobsUNRegRob07d$N))

# doing the loop
v <- NULL
mContRob07 <- mN800Rob07 <- mUNRegRob07 <- list ()
mContRob07.vcov <- mN800Rob07.vcov <- mUNRegRob07.vcov <- list ()

system.time (
  for (v in 1:length (vContRob07)){
    
    ## defining the explanatory variable of interest
    base$ivCont <- base[,vContRob07[v]]
    base$ivN800 <- base[,vN800Rob07[v]]
    base$ivUNReg <- base[,vUNRegRob07[v]]
    
    ## (i) Contiguous neighbors
    
    # country FE's (Polity)
    mContRob07[[v+0*length (vContRob07)]] <- summary (felm (after30_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    mContRob07[[v+1*length (vContRob07)]] <- summary (felm (postEle_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    mContRob07[[v+2*length (vContRob07)]] <- summary (felm (eprotest_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    
    # country RE's (Polity) (logit)
    mContRob07[[v+3*length (vContRob07)]] <- summary (glmer (after30_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    mContRob07[[v+4*length (vContRob07)]] <- summary (glmer (postEle_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    mContRob07[[v+5*length (vContRob07)]] <- summary (glmer (eprotest_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    
    # country FE's (V-Dem)
    mContRob07[[v+6*length (vContRob07)]] <- summary (felm (after30_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    mContRob07[[v+7*length (vContRob07)]] <- summary (felm (postEle_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    mContRob07[[v+8*length (vContRob07)]] <- summary (felm (eprotest_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    
    # country RE's (V-Dem) (logit)
    mContRob07[[v+9*length (vContRob07)]] <- summary (glmer (after30_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    mContRob07[[v+10*length (vContRob07)]] <- summary (glmer (postEle_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    mContRob07[[v+11*length (vContRob07)]] <- summary (glmer (eprotest_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    
    # country-year FE's
    mContRob07[[v+12*length (vContRob07)]] <- summary (felm (pbega2 ~ ivCont*ele30 | countryYear | 0 | country, data=base))$coef
    mContRob07.vcov[[v+12*length (vContRob07)]] <- felm (pbega2 ~ ivCont*ele30 | countryYear | 0 | country, data=base)$clustervcv
    
    
    ## (ii) 800km neighbors
    
    # country FE's (Polity)
    mN800Rob07[[v+0*length (vN800Rob07)]] <- summary (felm (after30_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    mN800Rob07[[v+1*length (vN800Rob07)]] <- summary (felm (postEle_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    mN800Rob07[[v+2*length (vN800Rob07)]] <- summary (felm (eprotest_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    
    # country RE's (Polity) (logit)
    mN800Rob07[[v+3*length (vN800Rob07)]] <- summary (glmer (after30_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    mN800Rob07[[v+4*length (vN800Rob07)]] <- summary (glmer (postEle_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    mN800Rob07[[v+5*length (vN800Rob07)]] <- summary (glmer (eprotest_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    
    # country FE's (V-Dem)
    mN800Rob07[[v+6*length (vN800Rob07)]] <- summary (felm (after30_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    mN800Rob07[[v+7*length (vN800Rob07)]] <- summary (felm (postEle_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    mN800Rob07[[v+8*length (vN800Rob07)]] <- summary (felm (eprotest_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    
    # country RE's (V-Dem) (logit)
    mN800Rob07[[v+9*length (vN800Rob07)]] <- summary (glmer (after30_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    mN800Rob07[[v+10*length (vN800Rob07)]] <- summary (glmer (postEle_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    mN800Rob07[[v+11*length (vN800Rob07)]] <- summary (glmer (eprotest_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    
    # country-year FE's
    mN800Rob07[[v+12*length (vN800Rob07)]] <- summary (felm (pbega2 ~ ivN800*ele30 | countryYear | 0 | country, data=base))$coef
    mN800Rob07.vcov[[v+12*length (vN800Rob07)]] <- felm (pbega2 ~ ivN800*ele30 | countryYear | 0 | country, data=base)$clustervcv
    
    
    ## (iii) UN region neighbors
    
    # country FE's (Polity)
    mUNRegRob07[[v+0*length (vUNRegRob07)]] <- summary (felm (after30_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    mUNRegRob07[[v+1*length (vUNRegRob07)]] <- summary (felm (postEle_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    mUNRegRob07[[v+2*length (vUNRegRob07)]] <- summary (felm (eprotest_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    
    # country RE's (Polity) (logit)
    mUNRegRob07[[v+3*length (vUNRegRob07)]] <- summary (glmer (after30_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    mUNRegRob07[[v+4*length (vUNRegRob07)]] <- summary (glmer (postEle_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    mUNRegRob07[[v+5*length (vUNRegRob07)]] <- summary (glmer (eprotest_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    
    # country FE's (V-Dem)
    mUNRegRob07[[v+6*length (vUNRegRob07)]] <- summary (felm (after30_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    mUNRegRob07[[v+7*length (vUNRegRob07)]] <- summary (felm (postEle_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    mUNRegRob07[[v+8*length (vUNRegRob07)]] <- summary (felm (eprotest_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1,]))$coef
    
    # country RE's (V-Dem) (logit)
    mUNRegRob07[[v+9*length (vUNRegRob07)]] <- summary (glmer (after30_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    mUNRegRob07[[v+10*length (vUNRegRob07)]] <- summary (glmer (postEle_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    mUNRegRob07[[v+11*length (vUNRegRob07)]] <- summary (glmer (eprotest_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1,], family=binomial (link="logit")))$coef
    
    # country-year FE's
    mUNRegRob07[[v+12*length (vUNRegRob07)]] <- summary (felm (pbega2 ~ ivUNReg*ele30 | countryYear | 0 | country, data=base))$coef
    mUNRegRob07.vcov[[v+12*length (vUNRegRob07)]] <- felm (pbega2 ~ ivUNReg*ele30 | countryYear | 0 | country, data=base)$clustervcv
  }
) ## 625 seconds


## (3.2.16) Bunce results (II): Electoral protest in last election in neighboring country (2000-2005 only)

# listing the explanatory variables
vContRob07b <- c ("n50_dEle_near_any", "n50_dEle_near_sum", "n50_dEle_Sizenear_any"
                  , "n50_dEle_wSucnear2_any2", "n50_dEle_wReprnear2_any2")
vN800Rob07b <- c ("n800_dEle_near_any", "n800_dEle_near_sum", "n800_dEle_Sizenear_any"
                  , "n800_dEle_wSucnear2_any2", "n800_dEle_wReprnear2_any2")
vUNRegRob07b <- c ("nUN_dEle_near_any", "nUN_dEle_near_sum", "nUN_dEle_Sizenear_any"
                   , "nUN_dEle_wSucnear2_any2", "nUN_dEle_wReprnear2_any2")

# running one model to get the number of observations
(sumNobsContRob07ba <- summary (NobsContRob07ba <- felm (pbega2 ~ n50_dEle_near_any | 0 | 0 | 0, data=base[base$year >= 2000 & base$year <= 2005,])))
(sumNobsContRob07bb <- summary (NobsContRob07bb <- felm (pbega2 ~ n50_dEle_near_any | countryYear | 0 | 0, data=base[base$year >= 2000 & base$year <= 2005,])))
(sumNobsContRob07bc <- summary (NobsContRob07bc <- felm (pbega2 ~ n50_dEle_near_any | 0 | 0 | country, data=base[base$year >= 2000 & base$year <= 2005,])))
(sumNobsContRob07bd <- summary (NobsContRob07bd <- felm (pbega2 ~ n50_dEle_near_any | countryYear | 0 | country, data=base[base$year >= 2000 & base$year <= 2005,])))

(sumNobsN800Rob07ba <- summary (NobsN800Rob07ba <- felm (pbega2 ~ n800_dEle_near_any | 0 | 0 | 0, data=base[base$year >= 2000 & base$year <= 2005,])))
(sumNobsN800Rob07bb <- summary (NobsN800Rob07bb <- felm (pbega2 ~ n800_dEle_near_any | countryYear | 0 | 0, data=base[base$year >= 2000 & base$year <= 2005,])))
(sumNobsN800Rob07bc <- summary (NobsN800Rob07bc <- felm (pbega2 ~ n800_dEle_near_any | 0 | 0 | country, data=base[base$year >= 2000 & base$year <= 2005,])))
(sumNobsN800Rob07bd <- summary (NobsN800Rob07bd <- felm (pbega2 ~ n800_dEle_near_any | countryYear | 0 | country, data=base[base$year >= 2000 & base$year <= 2005,])))

(sumNobsUNRegRob07ba <- summary (NobsUNRegRob07ba <- felm (pbega2 ~ nUN_dEle_near_any | 0 | 0 | 0, data=base[base$year >= 2000 & base$year <= 2005,])))
(sumNobsUNRegRob07bb <- summary (NobsUNRegRob07bb <- felm (pbega2 ~ nUN_dEle_near_any | countryYear | 0 | 0, data=base[base$year >= 2000 & base$year <= 2005,])))
(sumNobsUNRegRob07bc <- summary (NobsUNRegRob07bc <- felm (pbega2 ~ nUN_dEle_near_any | 0 | 0 | country, data=base[base$year >= 2000 & base$year <= 2005,])))
(sumNobsUNRegRob07bd <- summary (NobsUNRegRob07bd <- felm (pbega2 ~ nUN_dEle_near_any | countryYear | 0 | country, data=base[base$year >= 2000 & base$year <= 2005,])))

# getting the number of observations
(nobsContRob07b <- c (length (unique (base[!is.na (base$n50_dEle_near_any) & base$year >= 2000 & base$year <= 2005,]$country))
                      , length (unique (NobsContRob07bd$fe$countryYear))
                      , NobsContRob07bd$N))
(nobsN800Rob07b <- c (length (unique (base[!is.na (base$n800_dEle_near_any) & base$year >= 2000 & base$year <= 2005,]$country))
                      , length (unique (NobsN800Rob07bd$fe$countryYear))
                      , NobsN800Rob07bd$N))
(nobsUNRegRob07b <- c (length (unique (base[!is.na (base$nUN_dEle_near_any) & base$year >= 2000 & base$year <= 2005,]$country))
                       , length (unique (NobsUNRegRob07bd$fe$countryYear))
                       , NobsUNRegRob07bd$N))

# doing the loop
v <- NULL
mContRob07b <- mN800Rob07b <- mUNRegRob07b <- list ()
mContRob07b.vcov <- mN800Rob07b.vcov <- mUNRegRob07b.vcov <- list ()

system.time (
  for (v in 1:length (vContRob07b)){
    
    ## defining the explanatory variable of interest
    base$ivCont <- base[,vContRob07b[v]]
    base$ivN800 <- base[,vN800Rob07b[v]]
    base$ivUNReg <- base[,vUNRegRob07b[v]]
    
    ## (i) Contiguous neighbors
    
    # country FE's (Polity)
    mContRob07b[[v+0*length (vContRob07b)]] <- summary (felm (after30_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    mContRob07b[[v+1*length (vContRob07b)]] <- summary (felm (postEle_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    mContRob07b[[v+2*length (vContRob07b)]] <- summary (felm (eprotest_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    
    # country RE's (Polity) (logit)
    mContRob07b[[v+3*length (vContRob07b)]] <- summary (glmer (after30_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    mContRob07b[[v+4*length (vContRob07b)]] <- summary (glmer (postEle_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    mContRob07b[[v+5*length (vContRob07b)]] <- summary (glmer (eprotest_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    
    # country FE's (V-Dem)
    mContRob07b[[v+6*length (vContRob07b)]] <- summary (felm (after30_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    mContRob07b[[v+7*length (vContRob07b)]] <- summary (felm (postEle_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    mContRob07b[[v+8*length (vContRob07b)]] <- summary (felm (eprotest_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    
    # country RE's (V-Dem) (logit)
    mContRob07b[[v+9*length (vContRob07b)]] <- summary (glmer (after30_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    mContRob07b[[v+10*length (vContRob07b)]] <- summary (glmer (postEle_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    mContRob07b[[v+11*length (vContRob07b)]] <- summary (glmer (eprotest_dEle ~ ivCont + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    
    # country-year FE's
    mContRob07b[[v+12*length (vContRob07b)]] <- summary (felm (pbega2 ~ ivCont*ele30 | countryYear | 0 | country, data=base[base$year >= 2000 & base$year <= 2005,]))$coef
    mContRob07b.vcov[[v+12*length (vContRob07b)]] <- felm (pbega2 ~ ivCont*ele30 | countryYear | 0 | country, data=base[base$year >= 2000 & base$year <= 2005,])$clustervcv
    
    
    ## (ii) 800km neighbors
    
    # country FE's (Polity)
    mN800Rob07b[[v+0*length (vN800Rob07b)]] <- summary (felm (after30_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    mN800Rob07b[[v+1*length (vN800Rob07b)]] <- summary (felm (postEle_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    mN800Rob07b[[v+2*length (vN800Rob07b)]] <- summary (felm (eprotest_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    
    # country RE's (Polity) (logit)
    mN800Rob07b[[v+3*length (vN800Rob07b)]] <- summary (glmer (after30_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    mN800Rob07b[[v+4*length (vN800Rob07b)]] <- summary (glmer (postEle_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    mN800Rob07b[[v+5*length (vN800Rob07b)]] <- summary (glmer (eprotest_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    
    # country FE's (V-Dem)
    mN800Rob07b[[v+6*length (vN800Rob07b)]] <- summary (felm (after30_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    mN800Rob07b[[v+7*length (vN800Rob07b)]] <- summary (felm (postEle_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    mN800Rob07b[[v+8*length (vN800Rob07b)]] <- summary (felm (eprotest_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    
    # country RE's (V-Dem) (logit)
    mN800Rob07b[[v+9*length (vN800Rob07b)]] <- summary (glmer (after30_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    mN800Rob07b[[v+10*length (vN800Rob07b)]] <- summary (glmer (postEle_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    mN800Rob07b[[v+11*length (vN800Rob07b)]] <- summary (glmer (eprotest_dEle ~ ivN800 + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    
    # country-year FE's
    mN800Rob07b[[v+12*length (vN800Rob07b)]] <- summary (felm (pbega2 ~ ivN800*ele30 | countryYear | 0 | country, data=base[base$year >= 2000 & base$year <= 2005,]))$coef
    mN800Rob07b.vcov[[v+12*length (vN800Rob07b)]] <- felm (pbega2 ~ ivN800*ele30 | countryYear | 0 | country, data=base[base$year >= 2000 & base$year <= 2005,])$clustervcv
    
    
    ## (iii) UN region neighbors
    
    # country FE's (Polity)
    mUNRegRob07b[[v+0*length (vUNRegRob07b)]] <- summary (felm (after30_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    mUNRegRob07b[[v+1*length (vUNRegRob07b)]] <- summary (felm (postEle_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    mUNRegRob07b[[v+2*length (vUNRegRob07b)]] <- summary (felm (eprotest_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polity + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    
    # country RE's (Polity) (logit)
    mUNRegRob07b[[v+3*length (vUNRegRob07b)]] <- summary (glmer (after30_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    mUNRegRob07b[[v+4*length (vUNRegRob07b)]] <- summary (glmer (postEle_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    mUNRegRob07b[[v+5*length (vUNRegRob07b)]] <- summary (glmer (eprotest_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polity + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    
    # country FE's (V-Dem)
    mUNRegRob07b[[v+6*length (vUNRegRob07b)]] <- summary (felm (after30_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    mUNRegRob07b[[v+7*length (vUNRegRob07b)]] <- summary (felm (postEle_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    mUNRegRob07b[[v+8*length (vUNRegRob07b)]] <- summary (felm (eprotest_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag | country | 0 | country, data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,]))$coef
    
    # country RE's (V-Dem) (logit)
    mUNRegRob07b[[v+9*length (vUNRegRob07b)]] <- summary (glmer (after30_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    mUNRegRob07b[[v+10*length (vUNRegRob07b)]] <- summary (glmer (postEle_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    mUNRegRob07b[[v+11*length (vUNRegRob07b)]] <- summary (glmer (eprotest_dEle ~ ivUNReg + wdi_GDPcap_lag + pop_lag + polyarchy + physint_lag + (1|country), data=base[base$election_dEle==1 & base$year >= 2000 & base$year <= 2005,], family=binomial (link="logit")))$coef
    
    # country-year FE's
    mUNRegRob07b[[v+12*length (vUNRegRob07b)]] <- summary (felm (pbega2 ~ ivUNReg*ele30 | countryYear | 0 | country, data=base[base$year >= 2000 & base$year <= 2005,]))$coef
    mUNRegRob07b.vcov[[v+12*length (vUNRegRob07b)]] <- felm (pbega2 ~ ivUNReg*ele30 | countryYear | 0 | country, data=base[base$year >= 2000 & base$year <= 2005,])$clustervcv
  }
) ## 550 seconds


## (3.2.17) Anti-diffusion mechanisms: Civil liberties and media freedom

# listing the explanatory variables
vContRob08 <- c ("n50_d360_wequal_any", "n50_d360_wequal_sum", "n50_d360_wSize_any"
                 , "n50_d360_wequal_any_ch", "n50_d360_wequal_sum_ch", "n50_d360_wSize_any_ch")
vN800Rob08 <- c ("n800_d360_wequal_any", "n800_d360_wequal_sum", "n800_d360_wSize_any"
                 , "n800_d360_wequal_any_ch", "n800_d360_wequal_sum_ch", "n800_d360_wSize_any_ch")
vUNRegRob08 <- c ("nUN_d360_wequal_any", "nUN_d360_wequal_sum", "nUN_d360_wSize_any"
                  , "nUN_d360_wequal_any_ch", "nUN_d360_wequal_sum_ch", "nUN_d360_wSize_any_ch")

# variation in missing values
nrow (media[!is.na (media$pop_ch),]); nrow (media[!is.na (media$wdi_GDPcap_ch),]); nrow (media[!is.na (media$physint_ch),]); nrow (media[!is.na (media$polity_ch),]); nrow (media[!is.na (media$v2x_clpol_ch),]); nrow (media[!is.na (media$v2x_freexp_ch),])  ## low: Polity change; high: population change

# running one model to get the number of observations
(sumNobsContRob08a.low <- summary (NobsContRob08a.low <- felm (v2x_clpol_ch ~ n50_d360_wequal_any_ch + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | 0 | 0 | 0, data=media)))
(sumNobsContRob08b.low <- summary (NobsContRob08b.low <- felm (v2x_clpol_ch ~ n50_d360_wequal_any_ch + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | country | 0 | 0, data=media)))
(sumNobsContRob08c.low <- summary (NobsContRob08c.low <- felm (v2x_clpol_ch ~ n50_d360_wequal_any_ch + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | 0 | 0 | country, data=media)))
(sumNobsContRob08d.low <- summary (NobsContRob08d.low <- felm (v2x_clpol_ch ~ n50_d360_wequal_any_ch + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | country | 0 | country, data=media)))

(sumNobsN800Rob08a.low <- summary (NobsN800Rob08a.low <- felm (v2x_clpol_ch ~ n800_d360_wequal_any_ch + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | 0 | 0 | 0, data=media)))
(sumNobsN800Rob08b.low <- summary (NobsN800Rob08b.low <- felm (v2x_clpol_ch ~ n800_d360_wequal_any_ch + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | country | 0 | 0, data=media)))
(sumNobsN800Rob08c.low <- summary (NobsN800Rob08c.low <- felm (v2x_clpol_ch ~ n800_d360_wequal_any_ch + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | 0 | 0 | country, data=media)))
(sumNobsN800Rob08d.low <- summary (NobsN800Rob08d.low <- felm (v2x_clpol_ch ~ n800_d360_wequal_any_ch + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | country | 0 | country, data=media)))

(sumNobsUNRegRob08a.low <- summary (NobsUNRegRob08a.low <- felm (v2x_clpol_ch ~ nUN_d360_wequal_any_ch + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | 0 | 0 | 0, data=media)))
(sumNobsUNRegRob08b.low <- summary (NobsUNRegRob08b.low <- felm (v2x_clpol_ch ~ nUN_d360_wequal_any_ch + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | country | 0 | 0, data=media)))
(sumNobsUNRegRob08c.low <- summary (NobsUNRegRob08c.low <- felm (v2x_clpol_ch ~ nUN_d360_wequal_any_ch + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | 0 | 0 | country, data=media)))
(sumNobsUNRegRob08d.low <- summary (NobsUNRegRob08d.low <- felm (v2x_clpol_ch ~ nUN_d360_wequal_any_ch + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | country | 0 | country, data=media)))

(sumNobsContRob08a.high <- summary (NobsContRob08a.high <- felm (v2x_clpol_ch ~ n50_d360_wequal_any_ch | 0 | 0 | 0, data=media)))
(sumNobsContRob08b.high <- summary (NobsContRob08b.high <- felm (v2x_clpol_ch ~ n50_d360_wequal_any_ch | country | 0 | 0, data=media)))
(sumNobsContRob08c.high <- summary (NobsContRob08c.high <- felm (v2x_clpol_ch ~ n50_d360_wequal_any_ch | 0 | 0 | country, data=media)))
(sumNobsContRob08d.high <- summary (NobsContRob08d.high <- felm (v2x_clpol_ch ~ n50_d360_wequal_any_ch | country | 0 | country, data=media)))

(sumNobsN800Rob08a.high <- summary (NobsN800Rob08a.high <- felm (v2x_clpol_ch ~ n800_d360_wequal_any_ch | 0 | 0 | 0, data=media)))
(sumNobsN800Rob08b.high <- summary (NobsN800Rob08b.high <- felm (v2x_clpol_ch ~ n800_d360_wequal_any_ch | country | 0 | 0, data=media)))
(sumNobsN800Rob08c.high <- summary (NobsN800Rob08c.high <- felm (v2x_clpol_ch ~ n800_d360_wequal_any_ch | 0 | 0 | country, data=media)))
(sumNobsN800Rob08d.high <- summary (NobsN800Rob08d.high <- felm (v2x_clpol_ch ~ n800_d360_wequal_any_ch | country | 0 | country, data=media)))

(sumNobsUNRegRob08a.high <- summary (NobsUNRegRob08a.high <- felm (v2x_clpol_ch ~ nUN_d360_wequal_any_ch | 0 | 0 | 0, data=media)))
(sumNobsUNRegRob08b.high <- summary (NobsUNRegRob08b.high <- felm (v2x_clpol_ch ~ nUN_d360_wequal_any_ch | country | 0 | 0, data=media)))
(sumNobsUNRegRob08c.high <- summary (NobsUNRegRob08c.high <- felm (v2x_clpol_ch ~ nUN_d360_wequal_any_ch | 0 | 0 | country, data=media)))
(sumNobsUNRegRob08d.high <- summary (NobsUNRegRob08d.high <- felm (v2x_clpol_ch ~ nUN_d360_wequal_any_ch | country | 0 | country, data=media)))

# getting the number of observations
(nobsContRob08.low <- c (length (unique (NobsContRob08d.low$fe$country))
                         , NobsContRob08d.low$N))
(nobsN800Rob08.low <- c (length (unique (NobsN800Rob08d.low$fe$country))
                         , NobsN800Rob08d.low$N))
(nobsUNRegRob08.low <- c (length (unique (NobsUNRegRob08d.low$fe$country))
                          , NobsUNRegRob08d.low$N))
(nobsContRob08.high <- c (length (unique (NobsContRob08d.high$fe$country))
                          , NobsContRob08d.high$N))
(nobsN800Rob08.high <- c (length (unique (NobsN800Rob08d.high$fe$country))
                          , NobsN800Rob08d.high$N))
(nobsUNRegRob08.high <- c (length (unique (NobsUNRegRob08d.high$fe$country))
                           , NobsUNRegRob08d.high$N))

# doing the loop
v <- NULL
mContRob08 <- mN800Rob08 <- mUNRegRob08 <- list ()

system.time (
  for (v in 1:length (vContRob08)){
    
    ## defining the explanatory variable of interest
    media$ivCont <- media[,vContRob08[v]]
    media$ivN800 <- media[,vN800Rob08[v]]
    media$ivUNReg <- media[,vUNRegRob08[v]]
    
    ## (i) Contiguous neighbors
    
    # civil liberties as DV
    mContRob08[[v+0*length (vContRob08)]] <- summary (felm (v2x_clpol ~ ivCont | 0 | 0 | country, data=media))$coef
    mContRob08[[v+1*length (vContRob08)]] <- summary (felm (v2x_clpol ~ ivCont | country | 0 | country, data=media))$coef
    mContRob08[[v+2*length (vContRob08)]] <- summary (felm (v2x_clpol ~ ivCont + pop_lag + wdi_GDPcap_lag + physint_lag + polity | country | 0 | country, data=media))$coef
    
    # civil liberties (FD) as DV
    mContRob08[[v+4*length (vContRob08)]] <- summary (felm (v2x_clpol_ch ~ ivCont | 0 | 0 | country, data=media))$coef
    mContRob08[[v+5*length (vContRob08)]] <- summary (felm (v2x_clpol_ch ~ ivCont | country | 0 | country, data=media))$coef
    mContRob08[[v+6*length (vContRob08)]] <- summary (felm (v2x_clpol_ch ~ ivCont + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | country | 0 | country, data=media))$coef
    
    # media freedom as DV
    mContRob08[[v+6*length (vContRob08)]] <- summary (felm (v2x_freexp ~ ivCont | 0 | 0 | country, data=media))$coef
    mContRob08[[v+7*length (vContRob08)]] <- summary (felm (v2x_freexp ~ ivCont | country | 0 | country, data=media))$coef
    mContRob08[[v+8*length (vContRob08)]] <- summary (felm (v2x_freexp ~ ivCont + pop_lag + wdi_GDPcap_lag + physint_lag + polity | country | 0 | country, data=media))$coef
    
    # media freedom (FD) as DV
    mContRob08[[v+9*length (vContRob08)]] <- summary (felm (v2x_freexp_ch ~ ivCont | 0 | 0 | country, data=media))$coef
    mContRob08[[v+10*length (vContRob08)]] <- summary (felm (v2x_freexp_ch ~ ivCont | country | 0 | country, data=media))$coef
    mContRob08[[v+11*length (vContRob08)]] <- summary (felm (v2x_freexp_ch ~ ivCont + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | country | 0 | country, data=media))$coef
    
    
    ## (ii) 800km neighbors
    
    # civil liberties as DV
    mN800Rob08[[v+0*length (vN800Rob08)]] <- summary (felm (v2x_clpol ~ ivN800 | 0 | 0 | country, data=media))$coef
    mN800Rob08[[v+1*length (vN800Rob08)]] <- summary (felm (v2x_clpol ~ ivN800 | country | 0 | country, data=media))$coef
    mN800Rob08[[v+2*length (vN800Rob08)]] <- summary (felm (v2x_clpol ~ ivN800 + pop_lag + wdi_GDPcap_lag + physint_lag + polity | country | 0 | country, data=media))$coef
    
    # civil liberties (FD) as DV
    mN800Rob08[[v+3*length (vN800Rob08)]] <- summary (felm (v2x_clpol_ch ~ ivN800 | 0 | 0 | country, data=media))$coef
    mN800Rob08[[v+4*length (vN800Rob08)]] <- summary (felm (v2x_clpol_ch ~ ivN800 | country | 0 | country, data=media))$coef
    mN800Rob08[[v+5*length (vN800Rob08)]] <- summary (felm (v2x_clpol_ch ~ ivN800 + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | country | 0 | country, data=media))$coef
    
    # media freedom as DV
    mN800Rob08[[v+6*length (vN800Rob08)]] <- summary (felm (v2x_freexp ~ ivN800 | 0 | 0 | country, data=media))$coef
    mN800Rob08[[v+7*length (vN800Rob08)]] <- summary (felm (v2x_freexp ~ ivN800 | country | 0 | country, data=media))$coef
    mN800Rob08[[v+8*length (vN800Rob08)]] <- summary (felm (v2x_freexp ~ ivN800 + pop_lag + wdi_GDPcap_lag + physint_lag + polity | country | 0 | country, data=media))$coef
    
    # media freedom (FD) as DV
    mN800Rob08[[v+9*length (vN800Rob08)]] <- summary (felm (v2x_freexp_ch ~ ivN800 | 0 | 0 | country, data=media))$coef
    mN800Rob08[[v+10*length (vN800Rob08)]] <- summary (felm (v2x_freexp_ch ~ ivN800 | country | 0 | country, data=media))$coef
    mN800Rob08[[v+11*length (vN800Rob08)]] <- summary (felm (v2x_freexp_ch ~ ivN800 + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | country | 0 | country, data=media))$coef
    
    
    ## (iii) UN region neighbors
    
    # civil liberties as DV
    mUNRegRob08[[v+0*length (vUNRegRob08)]] <- summary (felm (v2x_clpol ~ ivUNReg | 0 | 0 | country, data=media))$coef
    mUNRegRob08[[v+1*length (vUNRegRob08)]] <- summary (felm (v2x_clpol ~ ivUNReg | country | 0 | country, data=media))$coef
    mUNRegRob08[[v+2*length (vUNRegRob08)]] <- summary (felm (v2x_clpol ~ ivUNReg + pop_lag + wdi_GDPcap_lag + physint_lag + polity | country | 0 | country, data=media))$coef
    
    # civil liberties (FD) as DV
    mUNRegRob08[[v+3*length (vUNRegRob08)]] <- summary (felm (v2x_clpol_ch ~ ivUNReg | 0 | 0 | country, data=media))$coef
    mUNRegRob08[[v+4*length (vUNRegRob08)]] <- summary (felm (v2x_clpol_ch ~ ivUNReg | country | 0 | country, data=media))$coef
    mUNRegRob08[[v+5*length (vUNRegRob08)]] <- summary (felm (v2x_clpol_ch ~ ivUNReg + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | country | 0 | country, data=media))$coef
    
    # media freedom as DV
    mUNRegRob08[[v+6*length (vUNRegRob08)]] <- summary (felm (v2x_freexp ~ ivUNReg | 0 | 0 | country, data=media))$coef
    mUNRegRob08[[v+7*length (vUNRegRob08)]] <- summary (felm (v2x_freexp ~ ivUNReg | country | 0 | country, data=media))$coef
    mUNRegRob08[[v+8*length (vUNRegRob08)]] <- summary (felm (v2x_freexp ~ ivUNReg + pop_lag + wdi_GDPcap_lag + physint_lag + polity | country | 0 | country, data=media))$coef
    
    # media freedom (FD) as DV
    mUNRegRob08[[v+9*length (vUNRegRob08)]] <- summary (felm (v2x_freexp_ch ~ ivUNReg | 0 | 0 | country, data=media))$coef
    mUNRegRob08[[v+10*length (vUNRegRob08)]] <- summary (felm (v2x_freexp_ch ~ ivUNReg | country | 0 | country, data=media))$coef
    mUNRegRob08[[v+11*length (vUNRegRob08)]] <- summary (felm (v2x_freexp_ch ~ ivUNReg + pop_ch + wdi_GDPcap_ch + physint_ch + polity_ch | country | 0 | country, data=media))$coef
  }
) ## 15 seconds


# saving
# system.time (save.image ("Replication Results BrancatiLucardi JCR Democracy Protests.RData"))
# system.time (save.image ("Replication Results BrancatiLucardi JCR Democracy Protests 2018-12-09.RData"))
